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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.