in reply to creating a new file with unique values
Or how I would probably write it:$file = "project.txt"; open(FILE,"$file"); my %hash = (); while(my $a=<FILE>) { if($a=~/\tCM+(\d*)/io) { print "$1\n"; $hash{$1}=undef; } } close FILE; open(OUTPUT,">> project.out"); while(my $key = each %hash) { print OUTPUT "$key\n"; } close OUTPUT;
my %done=(); open INPUT, "<$inputfile"; open OUTPUT, ">>$outputfile"; while(<INPUT>) { next unless /\tCM+(\d+)/io; next if exists $done{$1}; print OUTPUT, "$1\n"; $done{$1}=undef; ) close INPUT; close OUTPUT;
Haven't tested it, but it should work, and be fast... The <HANDLE> operator and regular expressions have the useful property that they both use the default variable ($_) if you supply none. This way you can bypass the use of $a.
|
|---|