in reply to Re: preserving hash value outside the loop
in thread preserving hash value outside the loop
1.txt @gi AGAT + AAAA 1:1.txt @gi CATT + AAAAA 3:1.txt
2.txt @gi AGAT + AAAA 1:2.txt @gi TACA + AAAA 2:2.txt
my code is:output.txt @gi AGAT + AAAA 2 1:1.txt 1:2.txt @gi CATT + AAAAA 3 3:1.txt @gi TACA + AAAA 2 2:2.txt
This gives me the count correct but $key is the last variable set. How can I print each value of $key with the total count and @{ $compare{$key1} }. I am new to perl so such a question. sorry if it sounds stupid.#!/usr/bin/env perl use strict; use warnings; my %compare; $/=""; my $key; my $value; while (<>) { chomp; ( $key, $value ) = split('\t', $_); my @lines = split /\n/, $key; my $key1 = $lines[1]; push( @{ $compare{$key1} }, $value ); } foreach my $key1 ( sort keys %compare ) { my $tot = 0; my $file_count = @ARGV; for my $val ( @{$compare{$key1}} ) { $tot += ( split /:/, $val )[0]; } if ( @{ $compare{$key1} } >= $file_count) { print join( "\t", $key, $tot, @{ $compare{$key1} } ), "\n\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: preserving hash value outside the loop -- silly oneliner
by Discipulus (Canon) on May 11, 2016 at 12:27 UTC | |
by Anonymous Monk on May 17, 2016 at 05:29 UTC | |
by Discipulus (Canon) on May 17, 2016 at 07:07 UTC |