atticus3000
atticus3000

Reputation: 409

How can I return a whole hash map in Perl?

I have a hash called

%values

Now I want to return the whole hash in a subroutine

sub getvalues {
  return $values;
}

But then I got an error, because $value needs a definition and my program stops. If I'm using

sub getvalues {
  return %values;
}

it seems to work, but my program is very slow and don't get further... So how can I return the whole map?

Upvotes: 1

Views: 659

Answers (1)

Nikhil Jain
Nikhil Jain

Reputation: 8352

It would be nice to return the hash reference instead of hash,what you need to do is

First stote the hash into the hash ref then return it like

sub getvalues {

    my %values = (test => "SO");

    my $values = \%values;

    return $values;
  }

Upvotes: 1

Related Questions