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


In reply to Re: more dbi issues by mkmcconn
in thread more dbi issues by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.