The following chunks behave the same in Perl 5.6 as in Perl 5.8. Notice the
output of branching statement modifiers vs. looping statement modifiers.
perl -e '$f=1; {local $f=2; print $f} print - $f\n'
# prints 2 - 1
perl -e '$f=1; {local $f=2 if 1; print $f} print - $f\n
# prints 2 - 1
Paul Seamons skribis 2005-04-15 11:50 (-0600):
my %h = a 1 b 2 c 3;
{
temp %h{$_} ++ for %h.keys;
Just make that two lines. Is that so bad?
temp %h;
%h.values »++;
%h.say; # values are incremented still
}
%h.say; # values are back to original values
Juerd
--
On Friday 15 April 2005 11:57 am, Juerd wrote:
Paul Seamons skribis 2005-04-15 11:50 (-0600):
my %h = a 1 b 2 c 3;
{
temp %h{$_} ++ for %h.keys;
Just make that two lines. Is that so bad?
temp %h;
%h.values »++;
For the given example, your code fits perfectly. A more common
Paul Seamons skribis 2005-04-15 12:16 (-0600):
For the given example, your code fits perfectly. A more common case I have
had to deal with is more like this:
my %h = a 1 b 2 c 3
my %other = a one b two;
{
temp %h{$_} = %other{$_} for %other.keys;
Either
temp %h;
%h{$_} =
temp %h;
%h{ %other.keys } = %other.values;
or even
temp %h{ %other.keys } = %other.values;
should work well already?
Almost - but not quite.
In Perl5
perl -MData::Dumper -e '%h=qw(a 1 b 2); {local %h; $h{a}=one; print Dumper
\%h} print Dumper \%h;
$VAR1 = {
'a' =
On Friday 15 April 2005 12:28 pm, Juerd wrote:
temp %h{ %other.keys } = %other.values;
Oops missed that - I like that for solving this particular problem. It does
even work in Perl5:
perl -MData::Dumper -e '%h=qw(a 1 b 2); {local @h{qw(a b)}=(one,two);
print Dumper \%h} print Dumper \%h'
Paul Seamons skribis 2005-04-15 12:41 (-0600):
In Perl5
perl -MData::Dumper -e '%h=qw(a 1 b 2); {local %h; $h{a}=one; print Dumper
\%h} print Dumper \%h;
$VAR1 = {
'a' = 'one'
};
$VAR1 = {
'a' = '1',
'b' = '2'
};
I'm imaging the behavior
I would like to get rid of all those implicit scopes. The only
exception would be that any topicalizing modifier allocates a private
lexical $_ scoped to just that statement. But dynamic scoping may
happen only at explicit block boundaries.
I can see the argument for the other side, where any
I'm imagining it will be different, as I expect temp to not hide the old
thing. I'm not sure it will.
That is another good question. I just searched through the S and A's and
couldn't find if temp will blank it out. I am thinking it will act like
local. Each of the declarations my, our and
Paul Seamons skribis 2005-04-15 13:42 (-0600):
Each of the declarations my, our and local currently set the value to
undefined (unless set = to something).
That's not true.
use strict;
$::foo = 5;
our $foo;
print $foo; # 5
Juerd
--
10 matches
Mail list logo