in reply to select only duplicate entries
my %h; while ( defined ( $_ = <DATA> )){ chomp; my ( $k, $v) = split ' '; push @{$h{$k}}, $v; } open my $fh1, '>', '/tmp/1.txt' or die; open my $fh2, '>', '/tmp/2.txt' or die; for my $k ( sort keys %h ) { my $c = @{$h{$k}}; for ( @{$h{$k}}){ $c > 1 ? print $fh2 "$k\t$_\n" : print $fh1 "$k\t$_\n"; }} __DATA__ protein1 stomach protein2 head protein3 muscle protein3 heart protein3 brain protein4 leg protein5 toes protein5 mouth protein6 ear
Boris
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: select only duplicate entries
by ikegami (Patriarch) on Aug 24, 2006 at 15:08 UTC | |
by borisz (Canon) on Aug 24, 2006 at 16:17 UTC |
In Section
Seekers of Perl Wisdom