in reply to How to delete lines with similar data


There is a lot of good advice in the previous posts and I think that you should take it into account.

However, apart from gellyfish, they also seem to have missed the point. ;-) To avoid duplicates in "NEWFILE" you could do something like the following:

#!/usr/local/bin/perl -w use strict; open REGFILE, "projects.dat" or die "Error message here: $!\n"; open NEWFILE, "+>>subscribe.dat" or die "Error message here: $!\n"; # Rewind the file for reading seek(NEWFILE, 0, 0); # Store all lines in NEWFILE in %seen using a hash slice my %seen; @seen{<NEWFILE>} = undef; while (<REGFILE>) { if (not exists $seen{$_}) { $seen{$_} = undef; # Do your split etc here print NEWFILE $_; } } close (NEWFILE); close (REGFILE);

--
John.

Replies are listed 'Best First'.
Re: Re: How to delete lines with similar data
by Jeffro Tull (Novice) on Feb 05, 2002 at 14:21 UTC
    This is to everyone who responded-

    I appreciate all the great feedback. I am very new at Perl and therefore, very green. I am learning as I go and your response has helped me a lot.

    I did in the end go with a modified version of John's code. It was very close to what I wanted in the end and was easy enough for me to modify to do exactly what I wanted.

    Thanks again for your help.

    Jeff