Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: push result into array

by ptum (Priest)
on Feb 26, 2007 at 22:10 UTC ( #602233=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://602233]
help
Chatterbox?
[stevieb]: I'm learning that no matter how good a piece of software is at what it's supposed to do, it's a piece of shit without providing any API documentation. (Talking about C++ here currently). Seriously... write software for an embedded platform and make...
[stevieb]: ...you guess based on the sparse examples, and the header files that are spread out illogically?
[stevieb]: document the public facing functions/methods people... ALL OF THEM.

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2017-05-28 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?