I need help to modify this code, so that it will also check for duplicates, for example if someone enters an email that already exists in the file.
open(FILE, "emails.dat");
@emails = <FILE>;
close(FILE);
if($#emails >= 4) {
&error;
} else {
open(FILE, ">>emails.dat");
print FILE "$email,$password\n";
close(FILE);
print "Location: $url\n\n";
}
}
I would really appreciate anyones help
Cheers
Linda
{my $logname; my $string; my $found=0;
open(db, "$logname");
my @Lines = <db>;
@Lines = sort(@Lines);
close(db);
foreach(@Lines,)
{if(index($_,"$string") >= 0)
{$found=-1;}}
if ($found!=-1)
{...add the entry...}
else
{...error message...}
open(FILE, "emails.dat");
@emails = <FILE>;
close(FILE);
@email_checker{@emails} = ();
if($#emails >= 4 ¦¦ exists $email_checker{$email}) {
&error;
} else {
open(FILE, ">>emails.dat");
print FILE "$email,$password\n";
close(FILE);
print "Location: $url\n\n";
}
}
If don't understand the trick, look up on Perl's "hash slices".