Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
First of all I'd just like to say that I think your code is really cool and that this program was a neat idea. I just made a few cosmetic changes to the code, please don't take any offense at this.

Things I Changed

  • Made it so that it compiles with -w and use strict.
  • Put an exit(0) command so that it doesn't print out 10 blank lines with the message if no arguments are supllied.
  • Added code to check if $ARGV[1] is supplied so that it doesn't print a message about an empty regular-expression.

    The (Slightly) Changed Code:

    #!/usr/bin/perl -w use strict; my $numargs = scalar @ARGV; if ($numargs == 0) { print "Clare's Random Password Generator\n"; print "Usage: pwdgen template [number]\n"; print "where template is a string composed of the following ch +aracters\n"; print "\tl\tlower case letter\n\tL\tupper case letter\n\tc\tlo +wer case consonant\n\tC\tupper case consonant\n"; print "\tl\tlower case vowel\n\tL\tupper case vowel\n\tn\tnumb +er\n\tp\tpunctuation mark\n\ta\tany character\n"; print "Any character in the template which is not one of those + above will be placed in the password at the same position\n"; print "number refers to the number of passwords to generate - +this defaults to 10.\n"; exit(0); } my $num; my $template = $ARGV[0]; if (defined $ARGV[1]) { if ($ARGV[1] =~ /^\d+$/) { $num = $ARGV[1]; } } else { $num = 10; } my @l = split '', 'qwertyuiopasdfghjklzxcvbnm'; my @n = split '', '0123456789'; my @p = split '', ',.?<>;:@/!"%^&*()-+=_'; my @L = split '', 'QWERTYUIOPASDFGHJKLZXCVBNM'; my @c = split '', 'qwrtypsdfghjklzxcvbnm'; my @C = split '', 'QWRTYPSDFGHJKLZXCVBNM'; my @v = split '', 'aeiou'; my @V = split '', 'AEIOU'; my @a = split '', 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBN +M,.?<>;:@/!"%^&*()-+=_0123456789'; my @t = split '', $template; my $len = scalar @t; my $newpass = ""; for (my $c = 0; $c < $num; $c++) { for (my $x = 0; $x < $len ; $x ++) { if ($t[$x] eq "l") { $newpass .= $l[rand @l]; next;} if ($t[$x] eq "L") { $newpass .= $L[rand @L]; next;} if ($t[$x] eq "c") { $newpass .= $c[rand @c]; next;} if ($t[$x] eq "C") { $newpass .= $C[rand @C]; next;} if ($t[$x] eq "v") { $newpass .= $v[rand @v]; next;} if ($t[$x] eq "V") { $newpass .= $V[rand @V]; next;} if ($t[$x] eq "n") { $newpass .= $n[rand @n]; next;} if ($t[$x] eq "p") { $newpass .= $p[rand @p]; next;} if ($t[$x] eq "a") { $newpass .= $a[rand @a]; next;} $newpass .= $t[$x]; } print "$newpass\n"; $newpass = ""; }

    -Ben Jacobs (dooberwah)
    one thing i can tell you is you got to be free
    http://dooberwah.perlmonk.org


    In reply to Re: Generic Password Generator by dooberwah
    in thread Generic Password Generator by claree0

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post; it's "PerlMonks-approved HTML":



    • Are you posting in the right place? Check out Where do I post X? to know for sure.
    • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
      <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
    • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
    • Want more info? How to link or How to display code and escape characters are good places to start.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others rifling through the Monastery: (2)
    As of 2024-04-20 05:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found