1. 程式人生 > >perl去除重複行和排序

perl去除重複行和排序

my($ref,$rec) = @ARGV;


if($#ARGV < 0 )
{
print "usage:perl count_rate.pl  $ref\n";
exit(-1);
}

#open(frec, "$rec") or die "can not open $rec\n";
open(fref, "$ref") or die "2\n";

open(fkey,">ref_key_$rec.txt") or die "4\n";

$refline2;
$reffer2;
%ref_hash;
$key;
@refarray = ();

 @refarray = <fref>;

@refarray2=();


for my $refline2 (@refarray)
{
chomp($refline2);
$ref_hash{$refline2}=$refline2;
    }
foreach  $key ( sort  keys %ref_hash)  #sort起到根據關鍵詞排序的功能
{
   chomp($key);
#print ("key is $key\n");
if($key=~/[\x80-\xFF]+?/)      #如果含有中文字元,可以不要
{
  push @refarray2, $key ;
  print ( fkey "$key\n");
}

}

close(fref);

close(fkey);