firstly Secode, don't use $a or $b, they are special variables used by Perl in sorting routines/

secondly, also always

use strict; use warnings;
use strict forces you to declare any new variables with my (or similar), so you'll avoid silly typos like
my $string = "why doesn't this print?"; print $strnig;
thirdly, always quote your barewords (by default use strict forces to do this too). What I mean by this is do...
my $string = "A"; # rather than my $string = A;
If this seems petty, then look at the following.
sub A { return 'B' }; # ... 1000 lines of complicated code ... my $string = A; print "$string\n"; # this prints "B"
Without knowing that A is a subroutine you could be forgiven for think your output might be A. Save yourself, and the people who maintain your code, the effort and clear up this ambiguity and always "use strict"

using warnings will give you handy hints, like when you use a variable but haven't defined a value for it yet. A lot of it's messages can be ignored, but they'll often give you hints to potential problems with your code.

Applying all this to your script gives you...

#/perl/usr/bin use warnings; use strict; my %line; my $why = ""; my $key_a = 'A'; my $key_b = 'B'; my $key_c = 'C'; $line{$key_a}{$key_b}{$key_c}; # this is line 12 my $i = 1; for my $loop_key_a (keys %line) { for my $loop_key_b (keys %{$line{$loop_key_a}}) { for my $loop_key_c (keys %{$line{$loop_key_a}{$loop_key_b}}) { print "$loop_key_a $loop_key_b $loop_key_c\n"; } } }
Which, when run, issues the warning "Useless use of hash element in void context at rja.pl line 12.", which might have been enough of a clue for you to figure this one out for yourself.

Happy Coding!

---
my name's not Keith, and I'm not reasonable.

In reply to Re: Hash code bug by reasonablekeith
in thread Hash code bug by Secode

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.