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

You could just add the new keys to the existing hash and make the same data serve both sets of keys:

foreach my $user (keys %dateuserfile) { for (keys %{$dateuserfile{$user}}) { $dateuserfile{$_}{$user} = $dateuserfile{$user}{$_}; } }
I won't vouch for the purity of design, but it ought to be efficient, giving two views of the identical data. Updates from one view will be seen from the other.

Update: ichimunki, rewrite line 5 as $hash{bar}{foo} = $hash{foo}{bar};. You're copying the value by including the deepest key. Leave off that last key and you get a copy ot the reference to the hash where it lives.

After Compline,
Zaxo

Replies are listed 'Best First'.
(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
    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}).