in reply to use 'local' modifier to hashref element
Yes, it works.
The clearest documentation on this, IMHO, is Temporary Values via local() in perlsub. Essentially, you can localize any hash or array value, which will be restored once you exit the current scope. This trick is frequently used with the %SIG handlers. When you do the localization, you are localizing the element in the hash that the reference points at.use strict; use warnings; use Data::Dumper; my $hash_ref = {1 => 2, 3 => 4}; BLOCK: { local $hash_ref->{1} = 5; print Dumper $hash_ref; } print Dumper $hash_ref;
Update: When to Still Use local() is actually the better doc link for this question.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: use 'local' modifier to hashref element
by schetchik (Beadle) on Jun 05, 2013 at 15:35 UTC | |
by kennethk (Abbot) on Jun 05, 2013 at 15:49 UTC | |
by nbtrap (Sexton) on Jun 06, 2013 at 01:03 UTC | |
by shmem (Chancellor) on Jun 06, 2013 at 13:56 UTC | |
by jakeease (Friar) on Jun 06, 2013 at 08:07 UTC | |
by rovf (Priest) on Jun 05, 2013 at 15:44 UTC | |
by kennethk (Abbot) on Jun 05, 2013 at 15:54 UTC | |
by Anonymous Monk on Jun 05, 2013 at 21:00 UTC | |
by rovf (Priest) on Jun 10, 2013 at 13:26 UTC |
In Section
Seekers of Perl Wisdom