[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Omaha.pm] Pulling data back out of a hash of arrays.
What I want to do:
Create a hash of arrays such that the key is the game id, and the rest of the
game data (currently just home and away teams) is the array. My print
statements tell me this seems to be working. Next I'd like to iterate
through the list of hash keys, and obtain the array contents for each key.
This is not working. I'm getting a pointer to the array. How do I get to
the actual data?
Code snippet:
while ( @fixture_rec = $sth->fetchrow_array ) {
my $game_id = $fixture_rec[0];
print "0=$fixture_rec[0] 1=$fixture_rec[1] 2=$fixture_rec[2]\n";
my @teams = @fixture_rec[1..2];
print "home=$teams[0] away=$teams[1]\n";
#stuff the hash
$fixture{$game_id} = [ @teams ];
}
return;
}
sub get_teamsheets {
while (($game_id, @teams) = each %fixture) {
print "Game=$game_id Home=$teams[0]\n";
}
return;
}
results:
0=2827 1=mba 2=mbb
home=mba away=mbb
0=2828 1=mbc 2=mbd
home=mbc away=mbd
0=2829 1=mbe 2=mbf
home=mbe away=mbf
0=2830 1=mbg 2=mbh
home=mbg away=mbh
0=2831 1=mbi 2=mbj
home=mbi away=mbj
Game=2828 Home=ARRAY(0x8338ad4)
Game=2830 Home=ARRAY(0x8338b34)
Game=2829 Home=ARRAY(0x8338b04)
Game=2831 Home=ARRAY(0x8338b64)
Game=2827 Home=ARRAY(0x8338a8c)