biologistatsea has asked for the wisdom of the Perl Monks concerning the following question:
Below is part of a script that I think should read a file into a hash, so I can look up the record using the key from other parts of the program. The print statements include are for trying to find out what's wrong! The program finds the name successfully (based on the print in the if loop), and creates the hash with the right values, but the keys are always empty (based on the output of the while loop that prints the hash)
open (NOV, '<', $novo); my %denovo; while (my $line = <NOV>){ chomp $line; if ($line =~ /([^,]*)$/){ my $name = "$1"; print "name is $name\n"; $denovo{$name} = "$line"; } } print "hash denovo is:\n"; while( my( $key, $value ) = each %denovo ){ print "$key: $value\n"; } close NOV;
I've tried changing the presence of / types of commas around $name when defining each hash entry. The keys should look like following: R2b.9138.9138.2(intensity=1341005.0692)_2 so I've tried using simpler names in case there were some illegal characters or something - but nothing works! I think I must be misunderstanding something fairly fundamental. Any help would be enormously appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why are my hash keys undefined?
by choroba (Cardinal) on Feb 08, 2016 at 17:13 UTC | |
by Anonymous Monk on Feb 08, 2016 at 17:43 UTC | |
by choroba (Cardinal) on Feb 08, 2016 at 17:46 UTC | |
by biologistatsea (Acolyte) on Feb 09, 2016 at 13:52 UTC | |
|
Re: Why are my hash keys undefined?
by Laurent_R (Canon) on Feb 08, 2016 at 17:57 UTC | |
|
Re: Why are my hash keys undefined?
by dorko (Prior) on Feb 08, 2016 at 19:55 UTC |