Tanalis has asked for the wisdom of the Perl Monks concerning the following question:
Update: Some more digging and I've answered my own question: Old Perl Behavior(TM). This behaviour was changed in Perl 5.6.1 (changelog) to make access to hash elements faster. More ammunition for the Update the Perl Version Campaign ... :)
I've been bitten this morning by some interesting behaviour when performing regular expression substitution on the values of a hash.
I've been bitten this morning by some interesting behaviour when performing regular expression substitution on the values of a hash.
I'm used to being able to do something like
to an array, and expected a similar thing to work for hashes:foreach( @array ) { s/something/something_else/g }
but it appears that this isn't the case. The substitution is performed, but on a copy of the original value, not a reference to it. Of course,foreach( values %hash ) { s/something/something_else/g }
works as expected.foreach( keys %hash ) { $hash{$_} =~ s/something/something_else/g; }
This interests me, and appears a little inconsistent. Is there some reason that my coffee-deprived brain can't see this morning for this inconsistency to exist?
-- Foxcub
#include www.liquidfusion.org.uk
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Hash value modification
by sk (Curate) on Jul 25, 2005 at 08:08 UTC | |
Re: Hash value modification
by tlm (Prior) on Jul 25, 2005 at 12:34 UTC | |
Re: Hash value modification
by anonymized user 468275 (Curate) on Jul 25, 2005 at 08:57 UTC | |
Re: Hash value modification
by siliconGopher (Initiate) on Jul 25, 2005 at 12:21 UTC |
Back to
Seekers of Perl Wisdom