http://www.perlmonks.org?node_id=1024053


in reply to Re^3: Returning hash reference from a sub
in thread Returning hash reference from a sub

Need to store the data in a hash to return from the sub, if Dumper:
$VAR1 = { 'names' => 'mary', 'names' => 'john', 'names' => 'Doe', 'names => '' };

Replies are listed 'Best First'.
Re^5: Returning hash reference from a sub
by Corion (Patriarch) on Mar 18, 2013 at 14:13 UTC

    That's not how hashes work. A key can only appear once in a hash.

Re^5: Returning hash reference from a sub
by tobias_hofer (Friar) on Mar 18, 2013 at 14:13 UTC

    Hi, this won't work as you use the same keys.

    $VAR1 = { 'names' => 'mary', 'names' => 'john', 'names' => 'Doe', 'names => '' };
    Better try to make an array of hashes which would look like this:
    $VAR1 = [ { 'names' => 'mary'}, { 'names' => 'john'}, { 'names' => 'Doe'}, { 'names => ''} ];
    or
    $VAR1 = { 'names' => ['mary','john','Doe','']}; ];

      I know, wish it could be return as:
      $VAR1 = { 'names' => 'mary'}, { 'names' => 'john'}, { 'names' => 'Doe'}, { 'names => ''} ;
      }, {