Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Elegantly dereferencing multiple references

by Yary (Pilgrim)
on May 13, 2016 at 14:47 UTC ( [id://1162966]=note: print w/replies, xml ) Need Help??


in reply to Elegantly dereferencing multiple references

I agree with simply operating on the refs in-place. On the other hand, functional style is is good, and if you don't want to modify the input hashes, you can still have an elegant call/return by using refs throughout the code:
my $x = {"a" => "red"}; my $y = {"b" => "green"}; my $z = {"c" => "black"}; my ($new_x, $new_y, $new_z) = &modfifyHash($x, $y, $z); # original $x is unchanged, $new_x has new value print "\$x->{a} = $x->{a}\t\$new_x->{a} = $new_x->{a}\n"; sub modfifyHash { my ($x, $y, $z) = @_; # If we don't want to modify the originals, # then make a shallow copy for each $_ = { %$_ } for $x,$y,$z; $x->{ "a" } = "circle"; $y->{ "b" } = "square"; $z->{ "c" } = "rectangle"; return($x, $y, $z) }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (11)
As of 2024-04-23 21:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found