in reply to Several stupid questions about subs
You are right to be unimpressed with your text book! "Modern" Perl provides very good management of variable locality and you almost never need to use global variables. There are very good reasons for not using globalvariables if they can be avoided. Related to this is the mantra: always use strictures (use strict; use warnings;), which helps avoid some of the worst aspects of old school Perl variables ("package" variables) by forcing you to use "lexical" variables. That doesn't prevent you introducing global lexical variables however, that is something you have to dicipline yourself against.
local provides a way of reusing a (generally) package variable in a local (runtime) scope. my creates a new instance of a variable in a lexical scope (generally up to the enclosing } or end of the file). local still has valid uses, but unless you need local's special proerties, my is what you should go for.
|
|---|