in reply to Simple? problem accesssing elements in a hash

I don't see any obvious errors in your code. When %PCA is populated correctly, maybe @line doesn't contain what you think it does?

(You can also simplify your last line to read my @pos = @PCA{@lines};, see perldata for details).

Replies are listed 'Best First'.
Re^2: Simple? problem accesssing elements in a hash
by 0AP0 (Initiate) on Aug 29, 2008 at 10:58 UTC

    I found the error. Being told that it didn't look like a code problem and more like an input problem helped.

    It was in the initialization of the PCA hash the keys, instead of being numbers, had quotation marks around them.

      and the general answer for this is:
      debug.
      print out variables, if you're not sure what's in it.
      and even if you're sure.
      use Data::Dumper; $Data::Dumper::Useqq = 1; # print non-printable chars warn Dumper $blackbox;
        I agree. Strings appearing with quotes around them are sneaky ones, though. In this case the answer was more obvious looking at the input files than the output statements.