People telling you to use strict and use warnings are trying to save you time and frustration down the road. 'strict' enforces predeclaration of lexically scoped variables. Up to this point, you've been using package global variables. That's fine for a quick and dirty ten line script, but you'll quickly run out of gas on the superhighway if you never take advantage of lexical scoping.

This isn't the simplest of concepts, but it doesn't have to start out as difficult as it seems. To begin with, before you use any variable, declare it like this:

my $var; my %charnames; # etc...

This will, in the most basic sense, ensure that you're complying with strictures. The next step will be to learn why you're doing this, and how it's helpful. I recommend that if you're going to teach yourself Perl, you let one of the pros help out. Beg, buy, borrow, or steal the Llama book: Learning Perl, published by O'Reilly & Associates. That's the best starting point I can think of. It's where most of us began. ...at least most of us who began learning Perl after the book was published. ;)


Dave


In reply to Re: Declaring variables under 'use strict' by davido
in thread Declaring variables under 'use strict' by Yoda_Oz

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.