Perl Debate Time ;-)

Michael Fowler wolfm at pobox.alaska.net
Sat Mar 20 17:03:15 CST 1999


Personally, I consider local invaluable.  It makes the code I write, when
doing certain things, far more readable.  For example:

	# Without local
	my($backup_sig) = $SIG{__DIE__};
	$SIG{__DIE__} = 'IGNORE';	# ignore die requests

	# code you don't want killing the entire program if it dies
	# goes here

	$SIG{__DIE__} = $backup_sig;

As opposed to:

	# With local
	{
		local($SIG{__DIE__}) = 'IGNORE';
		# code you don't want killing the entire program if it dies
		# goes here
	}

To me, the latter is far cleaner, and easier to read.  This is my primary
use of local.

Most programmers who use local where they could use my are doing so for one
of several reasons:
	1) They think Perl 4 is still widely in use, and are trying to be
	   backward compatible.

	2) The program used to be Perl 4, and noone took the time to do a
	   search, replace, and test.

	3) The program still is Perl 4, and it miraculously worked with
	   Perl 5, so noone changed it.

The latter two, obviously, are dealing with legacy issues, and have more
complications.  The first, however, is impaired, imho.  Perl 4 is pretty
much phased out.

Welp, there are my two cents.


Respectfully,
Michael Fowler


On Sat, Mar 20, 1999 at 11:16:24AM -0900, Arthur Corliss wrote:
> Greetings:
> 
> One of the semi-contentious debates I see on the newsgroups is on the use of
> local vs my.  There's even been some rumbling about having local deprecated,
> though I doubt it'll ever be considered by the higher echelons.
> 
> I'm bringing it up here just to see what our local programmers are doing,
> which they prefer, and what instances they'd use one over the other.
> 
> Personally, I only use local (currently) for private subroutines within a
> subroutine.  I hate polluting namespace.  :-)  My, of course, is used for
> everything else, especially since I religiously use strict mode.
> 
> So, what preferences do you guys have?
> 
> 	--Arthur Corliss
> 	  Bolverk's Lair -- http://www.odinicfoundation.org/arthur/
> 	  "Live Free or Die, the Only Way to Live" -- NH State Motto



More information about the Anchorage-pm mailing list