[ABE.pm] Curious

Ricardo SIGNES rjbs-perl-abe at lists.manxome.org
Mon Dec 18 11:42:06 PST 2006


* "Faber J. Fedor" <faber at linuxnj.com> [2006-12-18T13:44:20]
> I'm debugging some code.  I've got a hash that looks like this:
> 
>   DB<10> x $dataHRef
> 0  HASH(0x870fa08)
>    19890131 => HASH(0x87e699c)
>       ...
> 
> 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;

As has been noted, it's a context issue.  I would advise that even this
solution:

  my ($date) = keys %$dataHRef;

is not great, since if there is more than one key, the order in which they keys
are returned is not ideal.  If you want the latest or earliest key, you'll need
to sort, or use more structure.

In the debugger, x defaults to list context.  Always check "x scalar FOO" also.

-- 
rjbs


More information about the ABE-pm mailing list