SPUG: Scoping Guidelines; comments?
jimfl
jimfl at colltech.com
Fri Feb 18 12:29:11 CST 2000
--Quoth Phillip Neal <phillipneal at hotmail.com> On Friday, February 18, 2000
8:04 AM +0000:
> My rules of thumb have always been:
>
> 1. Suspect everything is global
My, my, my.
At some point when a perl program gets to be a certain size I
use strict;
use vars qw($foo $bar %baz);
I also am generally in the habit of doing stuff like
foreach my $thing in (@stuff) {
my $tmp = munge($thing);
}
I generally only use 'local' when I have to, i.e.:
sub spit_it_out {
local *FILEHANDLE = shift;
my @stuff = @_;
print FILEHANDLE join("\n", @stuff);
}
or
{
local $SIG{__DIE__} = \&dont_die;
do_something_deadly;
}
My guideline would be use lexical scoping unless you understand why you
would need to use dynamic scoping, which boils down, for beginners, to
"Never, ever use 'local'." Don Knuth has a good philosophy: In the
earlier chapters I'm going to make statements which, by the time you get
to later chapters you will recognise as being blatantly false.
--
Jim Flanagan Collective Technologies
jimfl at colltech.com http://www.colltech.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
Email to majordomo at pm.org: ACTION spug-list your_address
More information about the spug-list
mailing list