Camilo Gonzalez wrote at Tue, 28 May 2002 19:45:53 +0200:
> Gurus,
>
> I've been having this problem in various permutations throughout my Perl life. For
>this particular
> function, I set $confirm_counter to 1. Then I use a foreach loop to send email to
>multiple
> recipients. Within the foreach loop, I increment $confirm_counter by using
>$confirm_counter++. I
> then use the value of $confirm_counter as a test for an if conditional. If the
>counter is one,
> then a confirmation email will be sent to the person who submitted the form. If not,
>the
> confirmation email will be skipped. This is to prevent any user from receiving more
>than one
> confirmation email. However, it seems that $confirm_counter is not being incremented
>and the user
> will receive as many as 7 email confirmations. Any ideas? I'm enclosing the code in
>question
> below.
>
> ....
> if ( $confirm_counter = "1"){
^^^
That's the problem.
You wanted a comparison, but you did an assignment.
Just use "==".
> if ( $send_confirmation_mail ) {
> open_sendmail_pipe(\*CMAIL, $mailprog);
> print CMAIL $xheader, "To:
> $email$realname\n$confirmation_text$confirm_counter";
> close CMAIL;
> }
> }
> ++$confirm_counter;
> ...
When the problem occurs often,
there's a trick to avoid:
if ( 1 == $confirm_counter ) { ... }
When you write a '=' instead of '==' the interpreter is complaining
before the script starts :-)
Greetings,
Janek
PS: I'd bet, it's the most done beginner's mistake.
Is there anybody who has already written a program to dedect it ?
(Like lint)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]