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 :(