On 3/28/06, Bowie Bailey <[EMAIL PROTECTED]> wrote:
> Mario R. Sanchez, Ph.D. wrote:
> > hi pDale
> >
> > this is the entire code ...
> > ============
> > while(my $row_href = $sth->fetchrow_hashref)
> >        {
> >         print "$row_href->{'area'}\n";
> >        }
> > foreach my $key (keys %$row_href)
> > {
> >     print "hi\n";
> >     print "$key = ".$row_href->{$key}."\n";
> > }
> > =================
> >
> > the "while" correctly outputs the values for the column/field "area"
> > - so the hash at that point has the data.
> >
> > the "foreach" outputs nothing - does not even enter the loop since the
> > "hi" does not print....
>
> $row_href is not defined when you are trying to print the keys.
> $row_href is only defined inside the while loop.
>
> Try this code:
> ============
> while(my $row_href = $sth->fetchrow_hashref)
> {
>     foreach my $key (keys %$row_href)
>     {
>         print "-------------------------------\n";
>         print "$key = ".$row_href->{$key}."\n";
>     }
> }
>

Now, Mario, you can see why posting code is important.  Also, if you had:
   use strict;
   use warnings;
at the top of your script, it would have told you that $row_href did
not exist (was not defined) at the point you were trying to use it. 
You should always include those two lines to save yourself a world of
agravation.

If you are wanting to collect the data and use it later, you will need
to store it in a separate hash or array.

--
pDale Campbell

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to