Heredocs are a nice way to tidy up help messages and such. Consider:

sub DisplayUsage { print <<" USAGE"; Usage: genpass [-OPTIONS] LENGTH Generate secure passwords LENGTH characters long. -s, --symbols\t\tExclude symbol characters. -n, --numbers\t\tExclude number characters. -u, --uppercase\t\tExclude uppercase characters. -l, --lowercase\t\tExclude lowercase characters. -q(X)\t\t\tCreate X number of passwords. --help\t\t\tDisplay this usage screen. Report bugs, comments, and questions to jbrown_home\@yahoo.ca USAGE }

Note also that the prototype has been omitted from the sub. Apart from exceptional cases, prototypes are not useful and tend to lead to subtle and hard to find bugs.

Note too that the white space is an important part of the here document tag. There is a nasty and subtle trap here - the white space must match exactly for the end of the document to be recognised.

I'd be inclined to rewrite the password generation sub a little: ;)

sub GenPass { my ($pwdlen, %flags) = @_; my $password=""; my $num; while (length ($password) < $pwdlen) { $num = GetRandNum (); if (($num >= 33 && $num <= 47) || ($num >= 58 && $num <= 64) | +| ($num >= 91 && $num <= 95) || ($num >= 123 && $num <= 126) ) { next if $flags{symbols} eq '0'; } if (($num >= 48 && $num <= 57)) { next if $flags{numbers} eq '0'; } if (($num >= 65 && $num <= 90)) { next if $flags{uppercase} eq '0'; } if (($num >= 97 && $num <= 122)) { next if $flags{lowercase} eq '0'; } redo; # Invalid character, try again } continue { $password .= chr($num); } return "$password\n"; }

Main points are:


DWIM is Perl's answer to Gödel

In reply to Re: genpass Password Generator by GrandFather
in thread genpass Password Generator by munkyeetr

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.