Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > RE: hash return...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 5 Topic 11001 of 11532
Post > Topic >>

RE: hash return from a sub

by andrew.curry@[EMAIL PROTECTED] (Andrew Curry) Apr 29, 2008 at 12:03 AM

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.
 




 5 Posts in Topic:
hash return from a sub
flyzone@[EMAIL PROTECTED]  2008-04-28 10:06:06 
RE: hash return from a sub
andrew.curry@[EMAIL PROTE  2008-04-29 00:03:01 
Re: hash return from a sub
rob.dixon@[EMAIL PROTECTE  2008-04-29 00:17:02 
Re: hash return from a sub
noreply@[EMAIL PROTECTED]  2008-04-29 01:18:00 
Re: hash return from a sub
flyzone@[EMAIL PROTECTED]  2008-04-29 02:02:26 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 6:21:20 CDT 2008.