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"; } }
In reply to Re^2: preserving hash value outside the loop
by Anonymous Monk
in thread preserving hash value outside the loop
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |