I have an example from Shawn C. from another thread, presented here
out of context. The code does just what he meant it to do.
It inverts a hash.
Just curious if there is a particular reason Shawn did not use the
reverse function:
my %hash = (
'./b/fb' => 'fb',
'./b/c/fd' => 'fd',
'./b/l/c/f2' => 'f2',
'./b/g/f/r/fc' => 'fc',
'./b/g/h/r/fb' => 'fb'
);
my %inv_hash = reverse %hash;
my %inv_hash = reverse %hash;
print '%inv_hash: ', Dumper \%inv_hash;
Output:
%inv_hash: $VAR1 = {
'f2' => './b/l/c/f2',
'fb' => './b/fb',
'fc' => './b/g/f/r/fc',
'fd' => './b/c/fd'
};
Note that fb has only one value.
Oh I didn't notice there were dup values. :)
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/