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 record
> set 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.
| | | [EMAIL PROTECTED] | I don't, and I'm not.
__/ | http://www.hjp.at/ | -- Jesse Erlbaum on dbi-users
pgpIX6LaU94eo.pgp
Description: PGP signature
