No, it's not a special case of #1. It's a special case of something that's unmentioned: creating temporary values in aggregates. Consider this:
#!/usr/bin/perl
use strict;
use warnings;
my @things = qw /foo bar baz/;
sub do_print {
print "@things\n";
}
sub show {
local $things[1] = 'qux';
do_print;
}
show;
do_print;
__END__
foo qux baz
foo bar baz
In the subroutine show, local is used to temporary set the value of the second element to something else. Upon leaving the block, the old value is restored.
This is not mentioned in Dominus' article, and this is what rinceWind is using. The fact that %ENV is special is irrelevant.
| [reply] [Watch: Dir/Any] [d/l] |
my $item = 'wibble';
my @things = qw /foo bar baz/;
local $things[1] = 'qux'; # Legal
local $item = 'wobble'; # Dies with 'Can't localize lexical variable
+ $item'
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
| [reply] [Watch: Dir/Any] [d/l] |
Creating temporary values in aggregates is mentioned under #6 (Dynamic Scope Revisited)
| [reply] [Watch: Dir/Any] |
Good point. I'd still say that it has a bit of #1 due to the magic of %ENV, but it is true that it is also creating a temporary value for a hash element. The @ARGV example, however, was using "normal" localization and affected the whole array.
| [reply] [Watch: Dir/Any] |