Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

(ichi) Re x 2: creating multiple views of a hash by reordering its key and values

by ichimunki (Priest)
on Jun 26, 2002 at 17:30 UTC ( #177448=note: print w/ replies, xml ) Need Help??


in reply to Re: creating multiple views of a hash by reordering its key and values
in thread creating multiple views of a hash by reordering its key and values

Updates from one view will be seen from the other.

They will? I tried the following:

#!/usr/bin/perl -w use strict; my %hash; $hash{foo}{bar}{x} = 'zoom!'; $hash{bar}{foo}{x} = $hash{foo}{bar}{x}; print "$hash{foo}{bar}{x}\n"; print "$hash{bar}{foo}{x}\n"; $hash{foo}{bar}{x} = '!mooz'; print "$hash{foo}{bar}{x}\n"; print "$hash{bar}{foo}{x}\n";
which outputs:
zoom! zoom! !mooz zoom!
Now, if maybe I'm misunderstanding what your code does, but while it gives two separate views of the data, it does not create a duplicate set of references to a single set of data... if my calculations are correct it creates a second copy of the data with new references to the second copy. Changes to one copy will not affect the other.
update: my fault for not paying attention to details! Thanks for clarifying zaxo. Of course, this is still less than optimal, since it would seem to make doing key reordering impossible for that last key (not that doing this was in the original requirements, but it's the kind of solution I'd be hoping for). Also, we do still have a potential key overwrite going on (think $hash{foo}{foo}{x}).


Comment on (ichi) Re x 2: creating multiple views of a hash by reordering its key and values
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-09-21 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (176 votes), past polls