At the top of your script, right after the shebang line, put the following three lines:

use strict; use warnings; use diagnostics;

This will do several things. You mentioned that you're (paraphrasing) "so new you don't know what you don't know..."

'use strict;' will force you to learn what it is you don't know; how to use lexical variables and scoping instead of package globals. It will also protect you from the pitfalls of unwittingly using soft references (symbolic refs -- something to leave alone for a good long while). And strictures will protect you from misspelling variable names.

'use warnings;' will cause Perl to warn you when you do things that turn out to often be indicitave of a common mistake. For example, using a variable only once, trying to rely on the value of a variable that never received a value, etc. You've already got warnings with the -w switch on the shebang line, but you get better control with the pragma instead of the commandline switch.

'use diagnostics;' will force Perl to become more verbose by explaining what its warnings and error messages mean, in greater detail.

If you do that, you will suddenly find yourself needing to revamp the script a little. Feel free to ask questions if you need an explanation of the outcome.


Dave


In reply to Re: Code Optimization v5.8.1 by davido
in thread Code Optimization v5.8.1 by bluethundr

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.