Gossamer Forum
Home : Products : DBMan : Customization :

Pulling email addresses

Quote Reply
Pulling email addresses
Looking for help in creating a text file of all email addresses in my database where the user has indicated "Yes" in field 13 of my default.cfg.
Nothing elaborate just a simple text file displaying email addresses.

Webmaster
http://www.izmirhigh.com/index.shtml
Quote Reply
Re: Pulling email addresses In reply to
Code:
my @emails;
Code:
open(DB,"</path/to/database_file") || die "Couldn't open database :!$";
while (<DB>) {
chomp;
split /\|/;
if ($_[12] =~ /yes/i) {
push @emails, $_[FIELD_NUMBER_OF_EMAIL];
}
}
close(DB);
Code:
open(DB,">/path/to/NEW_EMAIL_FILE") || die "Couldn't open database :!$";
foreach (@emails) {
print DB "$_\n";
}
close(DB);
Try that - not sure if it will work but it should.

Replace FIELD_NUMBER_OF_EMAIL with the field number in default.cfg




Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com

Quote Reply
Re: Pulling email addresses In reply to
Didn't work ... here's what I did ...

Created an "email.cgi" file like so
In Reply To:
#!/usr/local/bin/perl
my @emails;

open(DB,"</www43/web/izmirh/cgi-local/Database/default.db") || die "Couldn't open database :!$";
while (<DB>) {
chomp;
split /\|/;
if ($_[17] =~ /yes/i) {
push @emails, $_[13];
}
}
close(DB);

open(DB,">/www43/web/izmirh/cgi-local/Database/email.txt") || die "Couldn't open database :!$";
foreach (@emails) {
print DB "$_\n";
}
close(DB);
Note I changed
In Reply To:
if ($_[12] =~ /yes/i)
to
In Reply To:
if ($_[17] =~ /yes/i)
as it's field #17 that has the Yes/No indicator ... hope that was right.

I then created a blank email.txt file and uploaded both email.cgi and email.txt, further chmod email.cgi to 755.

Then tried to execute http://www.izmirhigh.com/...l/Database/email.cgi but get a 500 error.

Where'd I screw up?

JR

Webmaster
http://www.izmirhigh.com/index.shtml
Quote Reply
Re: Pulling email addresses In reply to
I thought you said field 13 was the Yes field?

The array starts at 0 to field 13 would become $_[12]

Try adding this to the bottom of the script ->

print "Content-type: text/html\n\n";
print "DONE";

Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com

Quote Reply
Re: Pulling email addresses In reply to
Paul,

Yr right, I totally screwed up what I was trying to ask! SORRY!

What I want is to make a list of the email addresses, in field 13, selecting on only those in field 17, that indicate Yes.

With yr reply I tried
In Reply To:
#!/usr/local/bin/perl

my @emails;

open(DB,"</www43/web/izmirh/cgi-local/Database/default.db") || die "Couldn't open database :!$";
while (<DB>) {
chomp;
split /\|/;
if ($_[17] =~ /yes/i) {
push @emails, $_[13];
}
}
close(DB);

open(DB,">/www43/web/izmirh/cgi-local/Database/email.txt") || die "Couldn't open database :!$";
foreach (@emails) {
print DB "$_\n";
}
close(DB);

print "Content-type: text/html\n\n";
print "DONE";
but that doesn't work either.

Here's a http://www.izmirhigh.com/default.txt of my default.cfg if that helps.

Again, sorry for the confusion.

JR


Webmaster
http://www.izmirhigh.com/index.shtml
Quote Reply
Re: Pulling email addresses In reply to
Ok try:

Code:
#!/usr/local/bin/perl

&main();

sub main {

my @emails;

open(DB,"</www43/web/izmirh/cgi-local/Database/default.db") || &error("Couldn't open database :!$");
while (<DB>) {
chomp;
split /\|/;
if ($_[16] =~ /Yes/i) {
push @emails, $_[12];
}
}
close(DB);

open(DB,">/www43/web/izmirh/cgi-local/Database/email.txt") || &error("Couldn't open database :!$");
foreach (@emails) {
print DB "$_\n";
}
close(DB);
print "Content-type: text/html\n\n";
print "DONE";
}
Code:
sub error {
my ($msg) = shift;
print "Content-type: text/html\n\n";
print $msg;
exit;
}
Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com

Quote Reply
Re: Pulling email addresses In reply to
Got it to work by further changing
In Reply To:
... &error("Couldn't open database :!$");
to
In Reply To:
&error("Couldn't open database :!\$");
and further changing
In Reply To:
if ($_[16] =~ /Yes/i) {
push @emails, $_[12];
to
In Reply To:
if ($_[17] =~ /Yes/i) {
push @emails, $_[13];
Thx a LOT for yr help.
JR

Webmaster
http://www.izmirhigh.com/index.shtml
Quote Reply
Re: Pulling email addresses In reply to
Yikes - thats a typo - should have been $! not !$ and the $ doesn't need escaping.

Also $_[12] and $_[16] should have been correct based on what you told me but nevermind, you got it working.

Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com