in reply to Finding duplicates

Maybe this code will start you on the right direction
use strict; my $newdata = '124|20030812|uiy|kjh|87'; my $db = "textfile.txt"; open (DATAFILE, "+<$db") or die $!; my $key = join("|", (split /\|/, $newdata)[1,4]); while (<DATAFILE>) { chomp; if (join("|", (split /\|/)[1,4]) eq $key) { close DATAFILE; exit; } } print DATAFILE $newdata,"\n"; close DATAFILE;
$newdata will be added to the text file if it is not already there. I would probably put this in a sub and do a return instead of an exit. This consumes no extra memory no matter how big textfile.txt gets.

--

flounder

Replies are listed 'Best First'.
Re: Re: Finding duplicates
by Anonymous Monk on Aug 13, 2003 at 12:32 UTC
    thanks