Shawn H Corey wrote: > Bruce Ferrell wrote: >> I have a database (mysql if it matters) and I can select columns and >> rows from it no problem. what I can't quite seem to see how to do is to >> take the columns I can select and put them into a 2 dimensional array. >> >> I tried this: >> >> @data = $sth->fetchrow_array(); >> >> and it got a two dimensional array of one element each and this: >> >> @rtn = $sth->fetchrow_array(); >> push(@data,@rtn) seems to get me a giant 1 dimensional array. >> >> I'm sort of at a loss >> >> TIA >> >> Bruce >> > > You have to create an array of arrays. > > push @data, [ @rtn ]; > > See: > perldoc perldsc http://perldoc.perl.org/perldsc.html > perldoc perllol http://perldoc.perl.org/perllol.html > perldoc perldata http://perldoc.perl.org/perldata.html > > OK if I read these right and I understand the results of my experiments correctly, this:
@rtn = $sth->fetchrow_array(); is giving me an array with two elements and this: push @data, [ @rtn ]; is giving me an array of 2 element arrays. Not good as what I want is 2 arrays each the length of the total rows returned. What it seems I need to do is something like this: my ( $current_level, $time ) = $sth->fetchrow_array(); push @data[0][#]->$current_level; push @data[1][#]->$time; ... repeat until out of rows Is that correct notation to add the variable to the end of the array(s)? -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] http://learn.perl.org/
