G'day eric_newbie,
Welcome to the monastery.
$hash{$seq++} = { BIN => $bin_num, COUNT => $count, }; creates a complex hash of hashes structure. I don't believe this is what you want; it's probably the reason you were unable to progresas your code beyond this point.
I would've started by storing the file data in a simple array; then used a simple hash for the merge.
#!/usr/bin/env perl -l use strict; use warnings; my @init = qw{1 20 2 0 2 1 3 0 3 0 3 1 7 0 8 2 9 1 9 2 10 3}; print "@init"; my %merge; $merge{$init[$_]} += $init[$_+1] for grep { not $_ % 2 } 0 .. $#init; my @out = map { $_, $merge{$_} } sort { $a <=> $b } keys %merge; print "@out";
Output:
1 20 2 0 2 1 3 0 3 0 3 1 7 0 8 2 9 1 9 2 10 3 1 20 2 1 3 1 7 0 8 2 9 3 10 3
[For future reference, please see the guidelines in "How do I post a question effectively?".]
-- Ken
In reply to Re: merge duplicate values in hash
by kcott
in thread merge duplicate values in hash
by eric_newbie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |