Hi Monks,
I am searching through a hash with multiple values per key, and printing out the contents. However, the second value is failing to print, although I can't see what is wrong with my syntax! I have used Data::Dumper to check that each key has two values, which is does. Can anyone see an error? Here is my code and some Data:Dumper contents. Cheers!
my %hash = map {($part1[$_] => [$part2[$_], $gp_ids[$_]])}0..$#part1;
#print "$#island_ids $#nonisland_ids $#plasmid_ids\n";
my %map;
@map{@island_ids} = ("island") x @island_ids;
@map{@nonisland_ids} = ("nonisland") x @nonisland_ids;
@map{@plasmid_ids} = ("plasmid") x @plasmid_ids;
while (my($k,$v) = each %hash) {
print "$map{$k}-$map{$v->[0]} $map{$v->[1]}\n";
}
use Data::Dumper;
print Dumper \%hash;
# output from hash:
island-plasmid
plasmid-island
plasmid-island
island-nonisland
plasmid-island
# output from Dumper:
'c6679893-6679264
' => [
'39687-39872
',
'1'
],
'c4702714-4702079
' => [
'c78072-77437
',
'138'
],
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.