AW: returning hashes, and arrays
From: B. Fongo (perl_at_fongo.de)
Date: 03/18/04
- Next message: Charles K. Clarkson: "RE: returning hashes, and arrays"
- Previous message: Stuart White: "returning hashes, and arrays"
- In reply to: Stuart White: "returning hashes, and arrays"
- Next in thread: Stuart White: "Re: AW: returning hashes, and arrays"
- Reply: Stuart White: "Re: AW: returning hashes, and arrays"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: <beginners@perl.org> Date: Thu, 18 Mar 2004 02:50:13 +0100
That should work provided you're returning only on list.
It is much better to use reference when passing or retrieving more than
one value.
For instance: Retrieve the values from a sub as refereces.
($xRef, $yRef, $zRef) = example();
#
my @x = @$x;
my @y = @$y;
my $z = $$z;
sub example {
do this and that;
# Return 3 values as refereces.
return (\ @x, \@x, \$z );
return \(@x, @y, $z);# Simpler
}
HTH
Babs
-----Ursprüngliche Nachricht-----
Von: Stuart White [mailto:poovite@yahoo.com]
Gesendet: Donnerstag, 18. März 2004 02:17
An: beginners@perl.org
Betreff: returning hashes, and arrays
I'm having trouble returning a hash from a subroutine,
and an array from a different subroutine. "Beginning
Perl" said I could return a list, I can't get it to
work. Must the hash and array really be a reference
to the hash and array in order to return them?
Here's my subroutine:
sub ParseLineForHomeAndVisitors()
{
if ($_
=~/(Spurs|Suns|Mavericks|Lakers|Clippers|Cavaliers|Celtics|Pacers|Piston
s|Wizards|Warriors|Bulls|Hawks|Raptors|Magic|Heat|Kings|Rockets|Nuggets|
Grizzlies|Jazz|Knicks|Nets|Supersonics|'Trail
Blazers'|Bucks|Timberwolves|Hornets|Sixers|Bobcats)/)
{
@teams = /([[:alpha:]]+)/g;
}
return (@teams);
}
---------
And here's how I'm trying to capture the value:
@teams = ParseLineForHomeAndVisitors();
----
I tried the same thing with my hash:
CreateAbbrevAndNicknamesHash();
and here's the sub:
sub CreateAbbrevAndNicknamesHash()
{
my %AbbrevAndNicknames;
%AbbrevAndNicknames = (
IND=> "Pacers",
NJN=> "Nets",
DET => "Pistons",
NOH => "Hornets", #check this
MIL => "Bucks",
CLE => "Cavaliers",
BOS => "Celtics",
NYK => "Knicks",
MIA => "Heat",
PHI => "Sixers",
TOR => "Raptors",
ATL => "Hawks",
WAS => "Wizards",
ORL => "Magic",
CHI => "Bulls",
CHA => "Bobcats",
SAC => "Kings",
MIN => "Timberwolves",
SAN => "Spurs",
LAL => "Lakers",
DAL => "Mavericks",
MEM => "Grizzlies",
HOU => "Rockets",
DEN => "Nuggets",
UTA => "Jazz",
POR=> "Trail Blazers",
SEA => "Supersonics",
LAC => "Clippers",
GSW => "Warriors",
PHX => "Suns"
);
}
-----------
Any suggestions?
__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
- Next message: Charles K. Clarkson: "RE: returning hashes, and arrays"
- Previous message: Stuart White: "returning hashes, and arrays"
- In reply to: Stuart White: "returning hashes, and arrays"
- Next in thread: Stuart White: "Re: AW: returning hashes, and arrays"
- Reply: Stuart White: "Re: AW: returning hashes, and arrays"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|