#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Help, For the rndpass.pl


    I want to have Usage:
    rndpassword [-v] [-t <type>] [-n <length>]

    Options:
    -v version
    -t set character type (default: num)
    -n set length (default: 8 byte)

    Types: (output sample)
    alnum 0xaVbi3O2Lz8E69s # 0..9 a..z A..Z
    num 12378654 # 0..9

    Examples:
    shell> rndpassword <CR>
    Password: 01234567
    shell>

    shell> rndpassword -n 16 <CR>
    Password: 0123456789012345
    shell>

    shell> rndpassword -t alnum -n 4 <CR>
    Password: abcd
    shell>

    shell> rndpassword -v <CR>
    Version: 0.1
    Password: 01234567
    shell>

    shell> rndpassword -n 3 -v <CR>
    Version: 0.1
    Password: 012
    shell>

    shell> rndpassword -n 3 -v -n 4 <CR>
    Version: 0.1
    Password: 0123
    shell>
    but my code just doesnt work perfectlty
    #!/usr/bin/perl # password generator client (PROTOTYPE)
    # Peter Walsh csci 265
    use warnings "all";
    use Getopt::Std;
    use IO::Socket; $sock = new IO::Socket::INET (
    PeerAddr => '192.168.18.21',
    PeerPort => '7071',
    Proto => 'tcp' );
    die "Could not create socket: $!\n" unless $sock;

    Getopt::Std::getopts 'v:t:n' => my $opt = {};

    if( defined $opt->{n} and defined $opt->{t} )
    { printf STDERR "notice: -n and -t options are exclusive.\n";
    exit 1; }
    # length my $n = 8;
    if (defined $opt->{v} || 'default')
    { print "version:0.1\n"; }

    if( defined $opt->{n} )

    { print $sock "1:x&num:8\n" }
    if (defined $opt->{t} ) {
    print $sock "1:num:6\n"; }
    while (1) { $pass = <$sock>;
    chop $pass;
    last if $pass eq "CLOSE";
    print "$pass \n"; }
    Last edited by Hanxiang; October 13th, 2012 at 01:21 PM. Reason: fix code
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,954
    Rep Power
    1225
    my code just doesnt work perfectlty
    That's a very poor problem statement.

    In what way does it not "work perfectlty"?

    What is it doing which it shouldn't?

    What is it not doing which it should be doing?

    Please add the strict pragma
    Code:
    use strict;
    and fix the problems that it points out.

    IMO, Getopt::Long would be a better choice than Getopt::Std.

IMN logo majestic logo threadwatch logo seochat tools logo