Re: Parsing Results from fetchall_hashref()
- From: hjp@xxxxxxxxx (Peter J. Holzer)
- Date: Sun, 28 Oct 2007 16:29:21 +0100
On 2007-10-26 19:39:38 -0000, Rob Wilkerson wrote:
I'm trying to debug a problem in a Perl script that retrieves records
from an Oracle database and writes those records to a flat file. I'm
retrieving the records using fetchall_hashref() and have found that at
least one record isn't being written correctly so I'm trying to figure
out why.
I can access the value of each member just fine using $mediaref-
{$media_id}->{'ADID'} and I can access the size of the entire recordset as keys ( %$mediaref ). What I need to know, though, is how many
elements exist in $mediaref->{$media_id}, but I can't figure out
whether that's possible or how to do it. I've tried all kinds of
variations of keys ( %$mediaref->{$mediaid} ) with no luck at all.
scalar keys %{ $mediaref->{$mediaid} }
But I'm quite sure that will return the same number for all rows in the
query. Maybe you are more interested in the number of fields which are
not null:
scalar grep {
defined $mediaref->{$mediaid}{$_}
} keys %{ $mediaref->{$mediaid} }
Is it possible?
Yes.
Am I correctly guessing at how the system stores fields (i.e. as a nested
hash)?
Yes. No need to guess, though. perldoc DBI states that quite clearly:
The "fetchall_hashref" method can be used to fetch all the data to be
returned from a prepared and executed statement handle. It returns a
reference to a hash containing a key for each distinct value of the
$key_field column that was fetched. For each key the corresponding
value is a reference to a hash containing all the selected columns and
their values, as returned by fetchrow_hashref().
hp
--
_ | Peter J. Holzer | If I wanted to be "academically correct",
|_|_) | Sysadmin WSR | I'd be programming in Java.
| | | hjp@xxxxxxxxx | I don't, and I'm not.
__/ | http://www.hjp.at/ | -- Jesse Erlbaum on dbi-users
Attachment:
pgpBAELOnCO7Z.pgp
Description: PGP signature
- Follow-Ups:
- Re: Parsing Results from fetchall_hashref()
- From: Peter J. Holzer
- Re: Parsing Results from fetchall_hashref()
- References:
- Parsing Results from fetchall_hashref()
- From: Rob Wilkerson
- Parsing Results from fetchall_hashref()
- Prev by Date: Parsing Results from fetchall_hashref()
- Next by Date: Re: Parsing Results from fetchall_hashref()
- Previous by thread: Parsing Results from fetchall_hashref()
- Next by thread: Re: Parsing Results from fetchall_hashref()
- Index(es):
Relevant Pages
|
|