Re: Lifetime of my variables?



In <87lioeu4pt.fsf@xxxxxxxxxxxxxxx>, on 02/07/2012
at 02:56 PM, Peter Makholm <peter@xxxxxxxxxxx> said:

If you want to have a variable that keeps the vallue between each
time you enter the block, you should look at state variables.

I've got the opposite problem; I've got a variable that is supposed to
be undefrined at the beginning of each iteration and it's picking up a
value from a previous iteration. The program is rather large, but the
basic structure is

my $filer = $parser->filer;

...

mailfile: while (my $mailfile=shift) {

print STDOUT "\nunobfuscate.cmd processing file $mailfile\n";

my $entity = $parser->parse_open("$mailfile")
or die "$mailfile parse failed\n";

...

my $prevHELO;

...

print STDERR "\n\$prevHELO=$prevHELO\n";

...

}

foreach (@Received[$ReceivedIx..$#Received]) {

...

doReceived($+{FROM}, $+{HELO} // $+{IP}, $+{RDNS} // '', $+{IP},
$+{BY1}, $+{BY2} // '') || last;

...

sub doReceived {
...

if ($prevHELO) {
msg("\t\$prevHELO=$prevHELO\n");
msg("\t\$prevSrc=$prevSrc\n");
unless (uc $by1 eq $prevHELO or
"\U$by2.$by1" eq $prevHELO or
uc $by1 eq $prevSrc or
"\U$by2.$by1" eq $prevSrc) {
$prevHELO=$HELO;
msg("\t\$prevHELO after mismatch set to $prevHELO\n");
return undef();
}
if ($prevBogus) {
msg("\tPrevious Received field was bad; skipping $From\n");
return undef();
}
} elsif ($lookup && $MARF) {
$host_info{$IP}{MARF}=1 if $IP;
$host_info{$rDNS}{MARF}=1 if $rDNS;
}
$prevHELO=$HELO;
msg("\t\$prevHELO set to $prevHELO\n");
...
}
...
}

The intention is for each mailfile from the parameter list to start
out with a clean value of $prevHELO, but if I specify two files to the
script then the second file is processed with the residual value of
$prevHELO from the first file.

--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spamtrap@xxxxxxxxxxxxxxxxxx

.