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
--
http://convolution.nl/maak_juerd_blij.ht
> 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 an
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 "d
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
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'
>
> 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 = {
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 =
> my %other = ;
> {
> temp %h{$_} = %other{$_} for %other.keys;
Either
temp %h;
%h{$_} = %other{$_} for %other.k
On Friday 15 April 2005 11:57 am, Juerd wrote:
> Paul Seamons skribis 2005-04-15 11:50 (-0600):
> > my %h = ;
> > {
> > 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 commo
Paul Seamons skribis 2005-04-15 11:50 (-0600):
> my %h = ;
> {
> 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
--
http://convolution.nl