The values in %fixture are not arrays.  They are references to arrays.
You have to dereference them.

Here are a few ways you could do it:

###################################################

while(($game_id,$teamref) = each %fixture){
   #calling the array element using the reference
   print "Game=$game_id Home=$teamref->[0]\n";
}

NOTE:  You might have to do something like this:
   print "Game=$game_id Home=".$teamref->[0]."\n";

Or

while(($game_id,$teamref) = each %fixture){
   #dereferencing the array and making a copy
   my @teams = @{$teamref}; 
   print "Game=$game_id Home=$teams[0]\n";
}

Or

while(($game_id,$teamref) = each %fixture){
   #dereferencing the array on the fly
   print "Game=$game_id Home=${$teams}[0]\n";
}

Or

foreach my $game_id(sort keys %fixture){
   #a more key-centric way that allows you to sort
   print "Game=$game_id Home=".$fixture{$game_id}->[0]."\n";
}

DISCLAIMER:  I'm not in a place where I can test these; this is just to
give you some ideas.

####################################################



-----Original Message-----
From: Dave Thacker [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 22, 2005 10:28 PM
To: [email protected]
Subject: Retrieving Values from a HOA

Hello perlfolk.
Goal: Create a hash of arrays where 
         hash key = match number
         array[0] = home team
         array[1] = away team
and then retrieve the teams by retrieving all the keys

 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;
}

<snip>



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to