in reply to How to preserve all instances from a database in an array?

Your best bet is to read over DBI and become familiar with the various methods there. In particular, you might find selectall_arrayref suitable for this situation, which returns a reference to an array of array references (say that five times fast!):

use strict; use warnings; my $statement = "select foo, bar from mytable"; my $ary_ref = $dbh->selectall_arrayref($statement); if ($DBI::errstr) { # do something, your select failed! } my @rows = (); @rows = @{$ary_ref} if ref($ary_ref) eq 'ARRAY'; foreach my $thisrow (@rows) { my @columns = (); @columns = @{$thisrow} if ref($thisrow) eq 'ARRAY'; foreach (@columns) { print "$_\t"; } print "\n"; }

(Code untested.)

Update: One of the reasons your code didn't work was because you were storing your result row in two variables that immediately went out of scope, and you were overlaying the contents of @row each time through the loop. If you 'use strict;' and 'use warnings;' some of these things will become more obvious to you.

In my example above, I dereference the outer array reference to get the rows, and then for each row, I dereference again to get the columns. I did this deliberately in an explicit manner to show you how the array references work. There are several more compact ways to write this, once you understand what is going on.


No good deed goes unpunished. -- (attributed to) Oscar Wilde