Closed Thread Icon

Topic awaiting preservation: Perl and Email Addresses (Page 1 of 1) Pages that link to <a href="" title="Pages that link to Topic awaiting preservation: Perl and Email Addresses (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Perl and Email Addresses <span class="small">(Page 1 of 1)</span>\

Neurotic (0) Inmate
Newly admitted

From: fort lauderdale
Insane since: Jan 2003

posted posted 01-31-2003 19:52

I want to write a script that will allow me to let people automatically remove themselves from my mailing lists. The lists are in text files formatted as followed.,,b@v.ccom,

I want to be able to match an email and then remove it.


Lee Thornton

Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 01-31-2003 20:57

leeowc: Welcome. This could do with being in server-side scripting so that is where I'm sedning it.


FAQs: Emperor

Paranoid (IV) Inmate

From: California
Insane since: Jun 2000

posted posted 02-01-2003 03:05

Hi Lee,

This should get you started:

#!/usr/bin/perl -w
use strict;
use Fcntl ':flock';

my $db = '/path/to/email.db';
my $email = '';

# Read in file db file.
open (DB, "< $db") or die "Can't read open email DB: $!";
flock (DB, LOCK_SH);
read (DB, my $data, -s DB);
close DB;

# Find and remove the address from the db
if ($data =~ s/(,$email,)/,/m) {
open (DB, "> $db") or die "Can't write open email DB: $!";
flock (DB, LOCK_EX);
print DB $data;
close DB;

# Do something after you remove the address;
# Let the user know if the address was not found
else {
# Do something else when you can't find the address

The regx used to search for the email address assumes that there are no spaces between the comma and the address and that there is a comma after the last address in the db and before the first address in the db. You will have to adjust eh regex to match your data if needed.

If you get errors about the Fcntl module, look at the perl faq5 for more info on flocking your files.


[This message has been edited by Piper (edited 02-01-2003).]

Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 02-01-2003 06:15

nicely done, but wouldn't we want that regex to be global?

Code - CGI - links - DHTML - Javascript - Perl - programming - Magic -
ICQ: 67751342

Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 02-01-2003 06:33

nah there should only be one entry

.:[ Never resist a perfect moment ]:.

Paranoid (IV) Inmate

From: California
Insane since: Jun 2000

posted posted 02-01-2003 17:40

I guess that depends on how strict you are when you insert an address into the DB. I would would check to make sure that the address doesnt exists before inserting into the DB so that regex would work. But, without seeing the rest of the code, I think making it global would might be warranted.


« BackwardsOnwards »

Show Forum Drop Down Menu