in reply to Re^2: Understanding variable scope in perl
in thread Understanding variable scope in perl

For an answer about what "strict" does, see the output of perldoc strict.

Yes, I would say it's *almost* always a good idea to use "my".  It causes your variables to be lexically-scoped rather than globally-scoped, which can avoid many unintended bugs, and is considered an important programming practice.  (It's also one of the principles of object-oriented programming).

If you get into the habit of using it religiously, along with "strict" and "warnings", you'll avoid many pitfalls on your path to Perl enlightenment.  I was lucky enough to be steered onto the path of using the "-w" switch, (eg. perl -w), from almost the first time I started using Perl (the -w switch has the same effect as "warnings", which go hand-in-hand with "strict"), and it's saved me from countless headaches!

  • Comment on Re^3: Understanding variable scope in perl