#!/usr/bin/perl --
# filter.pl
use strict;
use warnings;
die "Usage: perl filter.pl pe_real_sample.txt > last.output\n"
unless @ARGV;
my %seen;
my @ary;
# push into @ary every line which have not be seen yet
while (my $line = <>) {
$line =~ /[fr] / or die "Can't parse line: $line";
my $key = $` . $';
push(@ary, [$line, $key]) unless $seen{$key}++;
}
# print all lines from @ary having $seen only once
print $_->[0] foreach grep {$seen{$_->[1]} < 2} @ary;
This script can be written more shortly:
#!/usr/bin/perl -n
/[fr] /, $s{$`.$'}++ || push @a, [$_,$`.$'] }{ $s{$_->[1]}<2 && print
+$_->[0] for @a
or even:
#!/usr/bin/perl -n
/f|r/,$s{$`.$'}++,push@a,[$_,$`.$']}{$s{$$_[1]}<2&&print$$_[0]for@a