I'm having a hair-pulling time with this one and I'm hoping someone will point me to a simple over-looked mistake.

The program reads data into a hash from one file, then goes through a few other files that contain lists of keys for the hash, and I'm trying to construct lists of hashed values from those keys.

The code, up to where it's going all pear-shaped, is as follows:

#!/usr/bin/perl -w use strict; use Statistics::Distributions; $|=1; open my $OUTPUT, ">", "mh_dist_outliers1d.tsv" or die $!; my %PCA=(); open my $PRCOMPFILE, "<", "strain_PCA.csv" or die $!; while (my $line=<$PRCOMPFILE>){ chomp $line; my @line=split /,/, $line; $PCA{$line[0]}=$line[1]; } close $PRCOMPFILE; my %results=(); my @sizes=(1,25,50,100); for my $size (@sizes){ print "\n###Starting pop$size###\n"; open my $POPLIST, "<", "pops.$size.tsv" or die $!; while (my $line=<$POPLIST>){ print "."; chomp $line; my @line=split /\t/, $line; my $pop=shift @line; my @pos= map {$PCA{$_};} @line;

The problem is when I get to the last line there $PCA{$_} is always returning "null", even if I hand-feed it keys from the hash. The debugger (in Komodo) shows the hash to be properly filled. I'd be most appreciative if someone can point out why I'm unable to access these hash elements.


In reply to Simple? problem accesssing elements in a hash by 0AP0

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.