Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

hakkum:

Just a few minor notes:

  • You're processing a command-line argument inside of random_password. That gives you a hidden data path that can be difficult to work with in a larger program.
  • Comments like # define variables are useless, as it's quite obvious that you're doing just that. If the code is obvious, you don't need the comment. If the code isn't obvious, then usually it's better to make it obvious rather than comment it. For example:
    # default password length $pass_len = 14;
    Would be better as:
    $dflt_pass_len = 14;
  • Declaring your variables at the point of use is better practice.
  • I prefer using return expression rather than expression to return a value to the caller.

Here's a slight update of the random_password subroutine for demonstration:

sub random_password { my ($pass_len) = @_; my @chars_in_pass = character_pool(); my $password=''; for (1..$pass_len) { my $random_number = int rand @chars_in_pass; $password .= $chars_pool[$random_number]; } return $password; }

I don't mean to indicate that your program is bad in any way. Overall, it's an impressive first program.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Please Review First Program: Random Password Generator by roboticus
in thread Please Review First Program: Random Password Generator by hakkum

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 sharing their wisdom with the Monastery: (2)
As of 2024-04-25 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found