Found browsing randomly, Anonymous asked months ago:
the sql statement can return multiple rows. can you help?
@list_of _teamdata = [][];
any suggesions??
</code>
Among other problems, it appears that he/she couldn't clearly visualize the structure of the data being created by the assignment to what DBI returned.
I wonder if Data::Dumper is what Anonymous needed, to see how the data should be structured, in order to access it as he/she seemed to be trying to do ?
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my @list_of_teamdata;
my $i = 0;
# Anonymous seems to want to coerce the data into a
# LoL structure similar to this
for (['game1',['lakers' ,'96' ],['blazers', '95' ]],
['game1',['bulls' ,'100' ],['lakers' , '107' ]],
['game1',['mavericks','90' ],['bulls' , '86' ]],
['game2',['bulls' ,'90' ],['lakers' , '88' ]],){
# And then put that into an array,
# (although hashes of lists keyed on 'round' in a hash
# keyed on 'year' might be more useful)
$list_of_teamdata[$i++] = $_;
}
# In such a structure, the data could be accessed this (ugly) way.
for (0..$#list_of_teamdata){
#for each game in the li
+st
print "$list_of_teamdata[$_][0]:\t", #print round
"$list_of_teamdata[$_][1]->[0]: ", #get hometeam
"$list_of_teamdata[$_][1]->[1]\t", #and scores
"$list_of_teamdata[$_][2]->[0]: ", #get visitor
"$list_of_teamdata[$_][2]->[1]\n\n"; #and scores
}
# but he/she may be equally as unclear about the data's structure
# as he/she was about how to create the
# structure needed
# that's why Data::Dumper is needed;
print Dumper([@list_of_teamdata]);
mkmcconn