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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.