문제

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?

도움이 되었습니까?

해결책

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;
  }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top