Brian wrote:

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.


Output of invert():
%inv_hash: $VAR1 = {
  'f2' => [
    './b/l/c/f2'
  ],
  'fb' => [
    './b/fb',
    './b/g/h/r/fb'
  ],
  'fc' => [
    './b/g/f/r/fc'
  ],
  'fd' => [
    './b/c/fd'
  ]
};

Both values of fb are preserved.


--
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

Eliminate software piracy:  use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to