From: perl <t...@asgweb.net>
> Cheers and thanks in advance for you help. I have a routine intended
> to purge duplicate emails from a list. The code below is not working.
> I remember seeing something like... foreach $email(@emails, @emails2))
> { etc ... but I'm lost. Any help is appreciated.
> sub purge
> {
> open (LIST, "$list") or error("$list  purge 1 email  ");
>         while (my $line = <LIST>)
>         {
> <snipped>
>         }
> close (LIST);
> <snipped>
> open (LIST, ">>$list") or error("$list  purge 2");
> flock(LIST, LOCK_EX);
> print LIST $newemail;
> close (LIST);

Your locking is wrong and even if all other scripts accessing the 
list locked correctly, this script could still cause problems. You 
should lock the file before you start reading from the file and keep 
the lock until you finish writing it. Besides ... you read the list, 
remove the duplicates (well attempt to) and then append the new list 
at the end of the original file. That doesn't look right either.

Jenda
===== je...@krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to