Ill make a guess it's a scope issue, but cant be sure without the main
code.
Try something like=20
use strict;
my %test=3Dmysub();
print %test;
sub mysub {
my(%myhash,$var1,$var2);
$var1 =3D '1';
$var2 =3D '2';
$myhash{$var1} =3D $var2;
print %myhash;
return ( %myhash );
}
This works fine from testing.
=20
-----Original Message-----
From: Flyzone [mailto:flyzone@[EMAIL PROTECTED]
28 April 2008 18:06
To: beginners@[EMAIL PROTECTED]
hash return from a sub
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 =3D ....;
var2 =3D ....;
$myhash{$var1} =3D $var2;
}
print %myhash; # all ok until here
return ( %myhash );
}
%test=3Dmysub();
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.
Thanks in advance.
--
To unsubscribe, e-mail: beginners-unsubscribe@[EMAIL PROTECTED]
For additional
commands, e-mail: beginners-help@[EMAIL PROTECTED]
http://learn.perl.org/
This e-mail is from the PA Group. For more information, see =
www.thepagroup.com.
This e-mail may contain confidential information. =20
Only the addressee is permitted to read, copy, distribute or otherwise =
use this email or any attachments. =20
If you have received it in error, please contact the sender immediately. =
=20
Any opinion expressed in this e-mail is personal to the sender and may =
not reflect the opinion of the PA Group.
Any e-mail reply to this address may be subject to interception or =
monitoring for operational reasons or for lawful business practices.


|