I wholeheartedly echo the strict and warnings sentiments of the other Monks.

As for your style in general, well, everyone has their own, and asking for comment on this subject is bound to yield many contradictory answers. However, there are at least two things your style must be: consistent and logical.

For example, why is it that you put parentheses around all my declarations even if you only declare one variable? The parentheses are needles unless you're declaring multiple variables with the same declaration. Granted, it's consistent, but not very logical. Notice, you do the exact opposite with print(); all calls to print() are completely devoid of parentheses, even if you supply multiple arguments to it. Why is that?

Try to come up some well-thought-out rules and use them constantly. For example, one I subscribe to is, when using built-in functions (which are thus prototyped), only use parentheses with named list operators and and only when your supplying more than one argument. E.g.:

# see: open(NAME, "< file") || die $!; print("one", "two", "three"); # and see: chop $string; carp "Some error."; # but see: print "a string"; my @stuff = split /\s/;

You get the idea. The thing is, you can only adopt and apply such a rule if you're reasonably familiar with Perl's built-in functions and what arguments they're prototyped to expect. If you're not, see perlfunc. Misunderstanding of built-ins and their precedence and prototypes is often the cause of inconsistent/needless usage of parentheses in beginner to intermediate Perl programmers' scripts.

One other thing I noticed was the comments. Throughout the script you switch between using single #, double ##, and even triple ###, and even then you mix things up by having some comments with a leading space between the last # and the text, and others with the text right after the last #.

Again, pick a style and stick with it.

The consensus in this area is, try to use only one # and have a leading space between the # and comment text. For example:

# a comment. # a multi- # line comment.
is typically easier to read than:
#a comment. #a multi- #line comment.

There are other things too, like how some assignment statements have spaces on both sides of = and others have no space between = and the lvalue and rvalue. Just try editing the script with logic and consistency in mind. And it wouldn't hurt to at least compare any new style rules you devise with the "official" ones in perlstyle, and then try to prove to yourself that your rules are better than perlstyle's; and if you can't, abandon your's and stick with perlstyle's.


In reply to Re: Script Review... by William G. Davis
in thread Script Review... by draxil42

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.