RE: hash return from a sub
- From: andrew.curry@xxxxxxxxxxxx (Andrew Curry)
- Date: Tue, 29 Apr 2008 00:03:01 +0100
Ill make a guess it's a scope issue, but cant be sure without the main
code.
Try something like
use strict;
my %test=mysub();
print %test;
sub mysub {
my(%myhash,$var1,$var2);
$var1 = '1';
$var2 = '2';
$myhash{$var1} = $var2;
print %myhash;
return ( %myhash );
}
This works fine from testing.
-----Original Message-----
From: Flyzone [mailto:flyzone@xxxxxxxxxxxxxxxx]
Sent: 28 April 2008 18:06
To: beginners@xxxxxxxx
Subject: 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 = ....;
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.
Thanks in advance.
--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx For additional
commands, e-mail: beginners-help@xxxxxxxx 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.
Only the addressee is permitted to read, copy, distribute or otherwise use this email or any attachments.
If you have received it in error, please contact the sender immediately.
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.
.
- Follow-Ups:
- Re: hash return from a sub
- From: Flyzone
- Re: hash return from a sub
- References:
- hash return from a sub
- From: Flyzone
- hash return from a sub
- Prev by Date: Re: web scraping
- Next by Date: RE: sql and perl
- Previous by thread: hash return from a sub
- Next by thread: Re: hash return from a sub
- Index(es):
Relevant Pages
|
|