Perl Debate Time ;-)

Tony tonyt at ptialaska.net
Sat Mar 20 16:00:05 CST 1999


On Sat, 20 Mar 1999, Arthur Corliss wrote:
> 
> While I like the local operator, let me play devil's advocate and repeat some
> of the arguments I've heard:
> 
> 	1)  Global variable space should be unpolluted as possible--any 
> 	    called subroutines should rely more on passed arguments than
> 		the checking of global variables.  If a global must be played
> 		with locally, copy the value to a 'my' variable and pass as an
> 		argument.
> 	2)  Readability suffers.  Perusing code is more difficult since you
> 	    now have to attempt to track the scope of variables by the same
> 		name.
> 
> Comments?

Use of "local" should be avoided, certainly.  However, in some cases, it
is desirable to override Perl's default global operators.  For instance,
if you want to put a stream filter on any <STD*> handles, "local" is
perfect.  And since "local" variables are generally defined within the
first few lines (usually after loading any modules), I don't think
readabilty suffers at all.

But, this is just my buck-ninety-five.  I could be wrong.  Certainly,
"local" is misused; but in some cases, it makes coding must plain easier,
and clearer.

						- Tony




More information about the Anchorage-pm mailing list