Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Why is DBI returning a ref to a ref to a ref to a list? (code)

by deprecated (Priest)
on Jun 12, 2001 at 22:34 UTC ( [id://87897]=perlquestion: print w/replies, xml ) Need Help??

deprecated has asked for the wisdom of the Perl Monks concerning the following question:

I ran into something strange when using DBI today. I found that it was returning a reference to a reference to a reference to a list. Why is this? Am I using the wrong call?
my @rv = $dbh -> selectall_arrayref( $commands, undef, ( $query ) ); foreach my $value (@rv) { my @deref = @{ $value }; foreach my $subval (@deref) { foreach my $ssval (@{$subval}) { print "$ssval"; <>; } } }
Thanks, bro dep.

--
Laziness, Impatience, Hubris, and Generosity.

Replies are listed 'Best First'.
(boo) Re: Why is DBI returning a ref to a ref to a ref to a list? (code)
by boo_radley (Parson) on Jun 12, 2001 at 22:44 UTC
    regarding my @rv = $dbh -> selectall_arrayref( $commands, undef, ( $query ) ); :

    @foo=$arrayref makes a one element array containing that reference. @foo=@{$arrayref} will probably do what you want. sample :

    $bar=1; @foo=$bar; print @foo,"\n"; $bar=["this","is","an","arrayref"]; @foo=$bar; print @foo,"\n"; @foo=@{$bar}; print @foo,"\n"; $bar=&baz; @foo=@{$bar}; print @foo,"\n"; @foo=@{&baz}; print @foo,"\n"; sub baz { return["this","is","also","an","arrayref"]; }
    OK?
Re: Why is DBI returning a ref to a ref to a ref to a list? (code)
by runrig (Abbot) on Jun 12, 2001 at 22:40 UTC
    From the DBI docs:
    This utility method combines the prepare, execute, and fetchall_arrayref entries elsewhere in this document into a single call. It returns a reference to an array containing a reference to an array for each row of data fetched.
    Your '@rv' should be '$rv'. It is a reference to an array.

    Updated:Oops. Correction. and boo_radley beat me to it anyway :(

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://87897]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-16 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found