Re: hash return from a sub



Flyzone wrote:
How can i return a copy of the hash? (The hash is build correct, but
return alsways null)
Here a sample of my code:

sub mysub {
while (.....) {
var1 = ....;
var2 = ....;
$myhash{$var1} = $var2;
}
print %myhash; # all ok until here
return ( %myhash );
}

%test=mysub();
print %test; # wrong, don't print nothing, neither error;

I would like to return a copy of the hash to a new variable, not a
reference.

Please post a short but _complete_ program that we can copy and run, and that demonstrates the issue. Don't forget to enable strictures and warnings, btw.

Then somebody can help you fix the code, if necessary.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.



Relevant Pages

  • Re: hash return from a sub
    ... return alsways null) ... print %myhash; ... to pass and return hashes by reference. ...
    (perl.beginners)
  • hash return from a sub
    ... How can i return a copy of the hash? ... return alsways null) ... print %myhash; ...
    (perl.beginners)
  • RE: hash return from a sub
    ... return (%myhash); ... How can i return a copy of the hash? ... This e-mail may contain confidential information. ...
    (perl.beginners)