PDA

View Full Version : Need Help (simple Perl script)



hogtied
10-12-2002, 01:07 AM
I've created a perl scritp that prints the users email address along with the date into and text file. The problem I'm having is that when I view the text file the date and email address is on two different lines.

Example:
date
E-mail address

What I want is:
date , email address
date , email address

I want to be able to import this into a database or spreadsheet, Hence the comma.

Here's the script:

#!/usr/local/bin/perl

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

$queryString = $ENV{'QUERY_STRING'};
@pairs = split (/&/, $queryString);
foreach $nameValue (@pairs)
{
($name, $value)= split (/=/, $nameValue);
$email{$name}=$value;
}

$date = `date`;

$emailFile = "newsletter.txt";

open (FILE, ">> $emailFile") || die ("Cannot Open File");
print FILE "$date";
print FILE "$email{'txtEmail'}";
close (FILE);

Thanks,
Hogtied

wap3
10-12-2002, 08:30 AM
I may be wrong here because im no expert but can you not change the last bit of your script to this:

open (FILE, ">> $emailFile") || die ("Cannot Open File");
print FILE "$date","$email{'txtEmail'}";
close (FILE);

The syntax might not be right but have a go.

Hope it helps

:)

Calilo
10-13-2002, 08:44 PM
Not sure if you already solve it but you can also do this:

open (FILE, ">> $emailFile") || die ("Cannot Open File");
print FILE ("$date , $email{'txtEmail'}");
close (FILE);

calilo

hogtied
10-17-2002, 03:09 AM
print FILE ("$date, $email{'txtEmail'}");

This coding prints to the file as follows:

Wed Oct 16 22:03:25 EDT 2002
, hhh@hhh.com

------------------------------------------------------

print FILE "$date","$email{'txtEmail'}";

This coding prints to the file as follows:

Wed Oct 16 22:07:30 EDT 2002
hhh@hhh.com

-----------------------------------------------

This is what i would like it to look like:

Wed Oct 16 22:07:30 EDT 2002, hhh@hhh.com


any suggestions????

Thanks
hogtied

hogtied
10-17-2002, 03:40 AM
Thanks people for you inputs but I've solved it one way. Not the way i want but it'll do.

print FILE "$email{'txtEmail'} , $date";

Thanks
hogtied :thumbsup: