First, please use <CODE> tags around your code. Second, always use strict and warnings
Now for your problem. If you have the memory, put your data into a hash. Don't print it to the output file until you've read all the data from the input file.
my $file = "project.txt"; # Use three-argument form of open() (available in perl 5.6.0) # and check the return value. open(FILE, '<', $project) or die "Can't open $project: $!\n"; my %input; while(my $line = <FILE>) { chomp $line; # Get rid of whitespace (newline) at the end of the str +ing if($line =~ /\tCM+(\d*)/io) { $input{$1}++; } } close(FILE);
After the above code runs, %input will contain the digits as keys, with the value being the number of times that key shows up in the input file. Printing to the output file is even easier. Just check if the value of in the %input hash is greater than 1 before printing:
open(OUT, '>>', 'project.out') or die "Can't open project.out for writ +ing: $!\n"; foreach my $i (keys %input) { print OUT "$i\n" unless $input{$i} > 1; } close OUT;
In reply to Re: creating a new file with unique values
by hardburn
in thread creating a new file with unique values
by afasch01
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |