Closed Thread Icon

Topic awaiting preservation: Perl and Email Addresses Pages that link to <a href="https://ozoneasylum.com/backlink?for=12601" title="Pages that link to Topic awaiting preservation: Perl and Email Addresses" rel="nofollow" >Topic awaiting preservation: Perl and Email Addresses\

 
Author Thread
leeowc
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. Something@you.com,A@v.com,b@v.ccom,c@v.com

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

Muahahahahahahahahaha

Lee Thornton

Emperor
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.

___________________
Emps

FAQs: Emperor

Piper
Paranoid (IV) Inmate

From: California
Insane since: Jun 2000

posted posted 02-01-2003 03:05

Hi Lee,

This should get you started:

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

my $db = '/path/to/email.db';
my $email = 'piper@dev-null.net';

# 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.

Regards,
Charlie



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

Petskull
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 - http://www.twistedport.com
ICQ: 67751342

bitdamaged
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 ]:.

Piper
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.

~Charlie

« BackwardsOnwards »

Show Forum Drop Down Menu