0AP0 has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Simple? problem accesssing elements in a hash
by moritz (Cardinal) on Aug 29, 2008 at 10:48 UTC | |
by 0AP0 (Initiate) on Aug 29, 2008 at 10:58 UTC | |
by tinita (Parson) on Aug 29, 2008 at 14:36 UTC | |
by 0AP0 (Initiate) on Aug 29, 2008 at 16:48 UTC |