> Kevin wrote:
>
> > Hello,
> >
> > I am having a bit of a problem working with nested data structures and
after
> > spending some time with the perl man pages, I am turning to the list for
> > help.
> >
> > I am reading a DBI record into a hash reference - my $row =
> > $sth->fetchrow_hashref() - I would like to create a hash to hold all of
the
> > returned rows (or thus, hashes) with the ID being the key, so for
example
> >
> > $returned_rows{$row->{'ID'}} = $row
> >
> > Essentially I would have a hash of hashes, holding the result set of the
> > query.
> >
> > My question is, how can I refer to the elements of a particular row? I
have
> > attempted:
> >
> > $returned_rows{11}{First_Name} and it returns no results (First_Name
being a
> > column).
>
>
> The easiest way to figure these things out is to dump the hash with
>
> Data::Dumper.
>
>
> use Data::Dumper; $Data::Dumper::Indent=1;
>
> print Data::Dumper->Dump([$row, $returned_rows], [qw($row
$returned_rows)]);
>
> That should give you the insight to figure it out.  If not, post the
> results for more help.

Bill,

Thanks for the reply. I have included the result set and some more of the
code. Your help is appreciated.


my $dbh = DBI->connect("DBI:XBase:C:/Perl/progs/customer") or die
$DBI::errstr;
my $sth = $dbh->prepare("select ID, First_Name from customer") or die
$dbh->errstr();
$sth->execute() or die $sth->errstr();
while (my $row = $sth->fetchrow_hashref()) {
    $returned_rows{$row->{'ID'}} = $row;
    print Data::Dumper->Dump([$row, $returned_rows], [qw($row
$returned_rows)]);
}

result:

$row = {
  'ID'=> '11',
  'First_Name'=> 'Tom'
  };
$returned_rows = undef;


When I attempt to put the Data::Dumper code outside of the while loop, I get
the following:

$row = undef;
$returned_rows = undef;

Thanks again.

Kevin.

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to