Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Variable in "if" statement

Reply
Thread Tools

Variable in "if" statement

 
 
blnukem
Guest
Posts: n/a
 
      08-17-2004
Hi all

I have this sub routine for sending email from my web site but it seems to
have a problem that I cant seem to figure out on the line that reads :

if($Name){
print MAIL "$Name: $Value \n";
}

Now I thought that this should only print if $Name has a value, it print all
the time cant figure it out.


CODE:

sub SendMail {

$FORM{'SendersName'} = lc($FORM{'SendersName'});
$FORM{'SendersName'} =~ s/([\w']+)/\u\L$1/g;
$FORM{'SendersEmail'} = lc($FORM{'SendersEmail'});

open (MAIL, "|$MailProg -t") or die("Can't open $MailProg!\n");
print MAIL "From: $FORM{'SendersName'}\n";
print MAIL "To: $Admin \n";
print MAIL "Subject: $FORM{'Subject'}\n";

print MAIL "Senders Name: $FORM{'SendersName'}\n";
print MAIL "Senders E-Mail: $FORM{'SendersEmail'}\n";
print MAIL "Senders Message: $FORM{'Message'}\n";

foreach $Pair (@Pairs) {
($Name, $Value) = split(/=/, $Pair);
$Name =~ tr/+/ /;
$Name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$Value =~ tr/+/ /;
$Value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$Name} = $Value;

next if (($Name eq "SendersEmail")||($Name eq "Subject")||($Name eq
"Message")
||($Name eq "SendersName"));

if($Name){
print MAIL "$Name: $Value \n";
}
}

close (MAIL);

exit;
}


Thanks in advance
Blnukem


 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      08-17-2004
blnukem <> wrote in comp.lang.perl.misc:
> Hi all
>
> I have this sub routine for sending email from my web site but it seems to
> have a problem that I cant seem to figure out on the line that reads :
>
> if($Name){
> print MAIL "$Name: $Value \n";
> }
>
> Now I thought that this should only print if $Name has a value, it print all
> the time cant figure it out.


Why would you think that? $value doesn't appear in the condition, how
is it supposed to know about it?

if ( $Name and $Value ) { ...

or probably

if ( defined( $name) and defined( $value) ) { ...

> CODE:


[snipped]

Anno
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      08-17-2004
blnukem wrote:
>
> if($Name){
> print MAIL "$Name: $Value \n";
> }
>
> Now I thought that this should only print if $Name has a value, it
> print all the time cant figure it out.


I don't understand what you mean. But I do understand that the code
you posted prints everything as message headers, and allows anybody to
use your script as a relay for sending anything to an unlimited number
of recipients...

Wouldn't it be a good idea to make use of a quality form-to-mail
script/module instead?

<code>

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
JJ
Guest
Posts: n/a
 
      08-17-2004
if($Name ne ""){
statements;
}


Vincent



"blnukem" <> schreef in bericht
news:TqmUc.20778$ et...
> Hi all
>
> I have this sub routine for sending email from my web site but it seems to
> have a problem that I cant seem to figure out on the line that reads :
>
> if($Name){
> print MAIL "$Name: $Value \n";
> }
>
> Now I thought that this should only print if $Name has a value, it print

all
> the time cant figure it out.
>
>
> CODE:
>
> sub SendMail {
>
> $FORM{'SendersName'} = lc($FORM{'SendersName'});
> $FORM{'SendersName'} =~ s/([\w']+)/\u\L$1/g;
> $FORM{'SendersEmail'} = lc($FORM{'SendersEmail'});
>
> open (MAIL, "|$MailProg -t") or die("Can't open $MailProg!\n");
> print MAIL "From: $FORM{'SendersName'}\n";
> print MAIL "To: $Admin \n";
> print MAIL "Subject: $FORM{'Subject'}\n";
>
> print MAIL "Senders Name: $FORM{'SendersName'}\n";
> print MAIL "Senders E-Mail: $FORM{'SendersEmail'}\n";
> print MAIL "Senders Message: $FORM{'Message'}\n";
>
> foreach $Pair (@Pairs) {
> ($Name, $Value) = split(/=/, $Pair);
> $Name =~ tr/+/ /;
> $Name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $Value =~ tr/+/ /;
> $Value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $FORM{$Name} = $Value;
>
> next if (($Name eq "SendersEmail")||($Name eq "Subject")||($Name eq
> "Message")
> ||($Name eq "SendersName"));
>
> if($Name){
> print MAIL "$Name: $Value \n";
> }
> }
>
> close (MAIL);
>
> exit;
> }
>
>
> Thanks in advance
> Blnukem
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a SQL statement with variable parameters and variable criteria Froefel ASP .Net 1 07-04-2007 09:38 AM
if statement that, when false, skips first statement in its block, executes second? Jay McGavren Java 11 01-16-2006 05:49 PM
How do I do a conditional statement in a constant statement? tkvhdl@gmail.com VHDL 3 12-16-2005 06:13 PM
exec "statement" VS. exec "statement in globals(), locals() Ted Python 1 07-22-2004 08:51 AM
exec "statement" VS. exec "statement" in globals(), locals() tedsuzman Python 2 07-21-2004 08:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57