Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Hash value modification

by sk (Curate)
on Jul 25, 2005 at 08:08 UTC ( [id://477714]=note: print w/replies, xml ) Need Help??


in reply to Hash value modification

 perldoc -f values

Note that the values are not copied, which means modifying them will modify the contents of the hash:

for (values %hash) { s/foo/bar/g }   # modifies %hash values

Can you give an example on what you are seeing?

SK

Update: Are you not seeing this behavior?

#!/usr/bin/perl -w my @array = qw(1 hello 2 hello 3 hellome 4 hellothere); my %hash = @array; foreach( values %hash ) { s/hello/hi/g; } print +("$_ = $hash{$_}\n") for (sort keys %hash);

Output

1 = hi 2 = hi 3 = hime 4 = hithere

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://477714]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-20 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found