Consider the following snippet:
#!/usr/bin/perl use Data::Dumper; my %h; { local $h{key} = 'blah'; # even "local $h{key};" will do # inititialization is only for clarity } print Dumper \%h;
In perl 5.6.1 the output is:
$VAR1 = { 'key' => undef };
while in 5.8.0 it is:
$VAR1 = {};
Digging through the documentation I found the following statement, in perldoc perlsub (in both 5.6.1 and 5.8.0 distributions):
The behavior of local() on non-existent members of composite types is subject to change in future.
Question 1: Can you provide me with some insight into the history of this development? Also, what lies ahead? The 5.8 behaviour looks more DWIMish IMHO - but the doc says that the behaviour may change. In which ways?
Question 2: While experimenting I wrote the following code to emulate 5.8 behaviour on 5.6:
# ... my %h; # ... my @local_keys = qw/foo bar baz/; my @inexistent = grep {! exists $h{$_}} @local_keys; { local @h{@local_keys}; # ... } delete @h{@inexistent}; # ...
You may notice the use of a hash slice as an argument to local. It came to me naturally (and it works). The question is: is this supported? My worries are based on my (possibly incorrect) belief that local and such are "special forms" and should be used only in ways sanctioned by the documentation (perldoc -f local is minimal and ambiguous). Also, why it works?
In reply to Perl 5.6 vs. 5.8: 'local' behaviour difference by calin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |