[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: [ID 20000123.003] [BUG our() 5.005_63] Lexical scoping problems.
Michael G Schwern wrote:
> as basically, "it scopes just like a my() variable except you can
> refer to it as a fully qualified variable"
>
> Okay, so color me stupid, but why is our()'s lexical scoping
> capabilities useful? Just for 'strict vars' reasons?
I can't see any situation where this is actually /necessary/, but as an
advocate of minimal scoping of variables, I have to approve :)
Consider a pair of functions that access the same data:
sub shove($) {
our @stack;
push @stack, shift;
}
sub prolapse() {
our @stack;
pop @stack
}
A contrived example, of course, but until now this could only have been
achieved either with a global (that would be visible throughout the
module from its declaration) or a closure, which is fine unless your
code is running under mod_perl or a similar re-packaging mechanism...
Pete
--
use Disclaimer::Standard;
my $phone='+44 1793 564450'; # "THIS IS THE COMPATIBILITY
my $fax='+44 1793 566918'; # POLICE. RESTORE YOUR ORIGINAL
my $mobile='+44 7973 725120'; # TOKE.C AND BACK AWAY SLOWLY."
- Follow-Ups from:
-
Larry Wall <larry@wall.org>
- References to:
-
Michael G Schwern <schwern@pobox.com>
Gurusamy Sarathy <gsar@ActiveState.com>
Michael G Schwern <schwern@pobox.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]