in reply to Declaring variables under 'use strict'

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