Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: more dbi issues

by mkmcconn (Chaplain)
on Nov 15, 2001 at 04:14 UTC ( #125468=note: print w/replies, xml ) Need Help??


in reply to more dbi issues

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://125468]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2023-04-02 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?