in reply to Hash code bug

This is a case where adding "use warnings" to the code will explain what is going on.

Useless use of hash elem in void context at ./hash line 9.

Line 9 is:

$line{$a}{$b}{$c};

and that code isn't doing anything (Note: well, it isn't doing what you think it's doing - see reasonablekeith's reply below for details). What do you think it should do?

You could also try printing the hash contents with Data::Dumper. You'll see that it's still empty and therefore your various calls to keys will all return empty lists.

If you change the line to:

$line{$a}{$b}{$c} = 1;

then the hash has been given some data to hold and all of your keys spring into existance.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Hash code bug
by reasonablekeith (Deacon) on Apr 28, 2006 at 08:30 UTC
       and that code isn't doing anything. What do you think it should do?

    That's not quite true. Perl will autovivify the first two keys. Dumper reveals %line to be...

    print Dumper(\%line); __OUTPUT__ $VAR1 = { 'A' => { 'B' => {} } };
    ---
    my name's not Keith, and I'm not reasonable.