Click to See Complete Forum and Search --> : Perl script help please


CurrentWave
07-24-2003, 01:07 AM
I have a Perl script I am trying to customize, but I only know PHP help!

Here is the top part of the original -
-----------------------
#!/usr/bin/perl

######################################################################
# Subject : This program will parse all the GET method data.
######################################################################

push (@INC, "perl5/lib");
print "Content-type: text/html \n\n";

$FORM_DATA = $ENV{'QUERY_STRING'};
foreach (split(/&/, $FORM_DATA))
{
($NAME, $VALUE) = split(/=/, $_);
$NAME =~ s/\+/ /g;
$NAME =~ s/%([0-9|A-F]{2})/pack(C,hex($1))/eg;
$VALUE =~ s/\+/ /g;
$VALUE =~ s/%([0-9|A-F]{2})/pack(C,hex($1))/eg;

# Find unique Variable Name for every variable coming in from the form input

$NUM = 0;
while ($MYVARS{$NAME} ne "")
{
$NUM++;
$NAME =~ s/\.([0-9]+$)|$/\.$NUM/;
}

# Store Variable NAME=Variable VALUE pair

$MYVARS{$NAME} = $VALUE;
}

$Success = "$MYVARS{'Status'}";
$ID = "$MYVARS{'ID'}";
$Name = "$MYVARS{'NameonCard'}";
$Street = "$MYVARS{'Cardstreet'}";
$City = "$MYVARS{'Cardcity'}";
$State = "$MYVARS{'Cardstate'}";
$Country = "$MYVARS{'Cardcountry'}";
$Email = "$MYVARS{'Email'}";
## You can receive the rest of the documented key=value pairs by following the code above. #
----------------------------------
And here is the part I'm adding -

use strict;
use Mail::Mailer;

If $Success = 1; {

my $body = "Another successful donation was made. \n";
$body = "Here is the information - \n";
$body = $ID "\n" $Name "\n\n" $Street "\n" $City " " $State " " $Country "\n" $Email "\n"

my $mailer = Mail::Mailer->new("sendmail");
$mailer->open({ From => "webmaster@kenwood.org",
To => "JMM@kenwood.org",
Subject => "A Donation was made",
});
print $mailer $body;
$mailer->close();

exit;
}
# This is the end of email
----------------------------------

Can some one touch up the syntax on the second email part that I have added. I've composed this from other scripts and it isn't completely right.

Do I need the exit; ? Because I have html that gets printed later on in the script and I don't want to break out of anything.

Thanks a bunch,

A Perl Neebie

Phil Karras
07-24-2003, 10:58 AM
This is wrong:
If $Success = 1;
It should be:

if ($Success == 1) { // use lower case I in if
# do this
}
else
# do this
}


Isn't that the same as PHP?

pyro
07-24-2003, 11:54 AM
Yep, that's the same structure as a PHP if loop...

Jeff Mott
07-24-2003, 01:22 PM
Well for starters, everything that is the original program can go. Use this instead.use CGI;
my $cgi = CGI->new();

my $Success = $cgi->param('Status');
my $ID = $cgi->param('ID');
my $Name = $cgi->param('NameonCard');
my $Street = $cgi->param('Cardstreet');
my $City = $cgi->param('Cardcity');
my $State = $cgi->param('Cardstate');
my $Country = $cgi->param('Cardcountry');
my $Email = $cgi->param('Email');If $Success = 1; {This has already been mentioned. The correct syntax of an if statement in Perl isif ($Success == 1) {or, since Perl treats any value except for 0, the empty string, and undef as true, it can be written this wayif ($Success) {$body = $ID "\n" $Name "\n\n" $Street "\n" $City " " $State " " $Country "\n"The concatenation operation in Perl is the period.$body = $ID . "\n" . $Name . "\n\n" . $Street . "\n" . $City . " " . $State . " " . $Country . "\n";And don't forget the semi-colon :). Also, since double quotes will interpolate variables, it can be writtent his way$body = "$ID\n$Name\n\n$Street\n$City $State $Country\n";"webmaster@kenwood.org"$ is the prefix for a scalar variable, and @ is the prefix for an array. And since double quotes will interpolate variables this will attempt to parse @kenwood as an array. You need to either backslash it"webmaster\@kenwood.org"or use single quotes'webmaster@kenwood.org'Same problem with your To field.Do I need the exit;Depends. If there is no other code following the if statement then no. If there is then you can either use exit to prevent the rest from being executed or enclose the rest in an else statement.