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

my @rec_data; while (my $data = $result->fetchrow_hashref) { push @rec_data, [ $data->{rec_no}, $data->{name}]; } for my $i ( 0 .. 9 ) { print $rec_data[$i]->[0]; print $rec_data[$i]->[1]; }
(did not compile this code) UPDATE: davidrw is of course right. I focused on your array question. the point is to push a reference in an array. you should read perldoc perlref.

Replies are listed 'Best First'.
Re^2: How to preserve all instances from a database in an array?
by davidrw (Prior) on Mar 23, 2006 at 23:05 UTC
    no point in using fetchrow_hashref if you're a) getting all the rows ("selectall" instead of "fetchrow") and b) want an array ("arrayref" instead of "hashref"):
    my @rec_data = @{ $db->selectall_arrayref($select) }; foreach my $i ( 0 .. $#rec_data ){ printf "%d) (recno,name)=(%s, %s)\n", $i+1, @{$rec_data[$i]}; }