I want to give more specifics on the use of strict and how it can make your life easier. Consider the following code:
$max_count = 100; $counter = 0; while( $counter < $max_count ){ $conter++; print "COUNT = $count" }

You would expect to see:

COUNT = 0 COUNT = 1 ... COUNT = 99

Instead you would see:

COUNT = 0 COUNT = 0 COUNT = 0 ...
And so on until you interupted the program. If this was from a more complex code sample, it may not be obvious at first that you were never incrementing the variable named "counter", but instead another variable named "conter".

With strict turned on, the code would look like this:

my $max_count = 100; my $counter = 0; while( $counter < $max_count ){ $conter++; print "COUNT = $count" }

The compilation would fail and you would be informed that there was no variable declared named 'conter'.

The reason for this is that Perl does not have strongly typed variables, which can lead to problems that only manifest themselves at runtime. Using strict is a way to get around some of these problems.


In reply to Re: Array manipulation by scmason
in thread Array manipulation by loop362

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.