[ABE.pm] Curious
Michael C. Toren
mct at toren.net
Mon Dec 18 11:06:20 PST 2006
On Mon, Dec 18, 2006 at 01:44:20PM -0500, Faber J. Fedor wrote:
> I did this
>
> DB<11> x keys %$dataHRef
> 0 19890131
>
> which is what I expected. So in my code I say
>
> 249: my $date = keys %$dataHRef;
>
> but
>
> DB<12> x $date
> 0 1
In the above, "keys %$dataHRef" is returning a list with one element.
You're then evaluating that list in scalar context, which returns the
number of elements in the list -- 1. If instead what you were hoping
for was the name of the first key, you can do:
my $date = (keys %$dataHRef)[0];
or:
my ($date) = keys %$dataHRef;
HTH,
-mct
More information about the ABE-pm
mailing list