in reply to push result into array
Heck, why do extra work when DBI already does it for you?
@dept = @{$sth->fetchall_arrayref()};
Now @dept holds a bunch of array references, one for each of your rows. You can step through @dept, dereference the array reference, and go to town on the columns you need:
use strict; use Data::Dumper; foreach my $thisrow (@dept) { if (ref($thisrow) eq 'ARRAY) { my @columns = @{$thisrow}; foreach (@columns) { # do something } } else { print "Hey! That's not an array reference!\n"; print Dumper($thisrow); } }
Admittedly, that is a little more explicit than I would actually do in practice -- no need for @columns when you can just talk about $thisrow->[2], for example.
|
---|
In Section
Seekers of Perl Wisdom