Janek said:
May I ask what the problem is you need to evaluate operators for.
Sure, maybe that's for the best.

I have tried eval and can't get
anything to work. I need to modify a script that represents my one and only
foray into Perl, it was done a year ago, and I'm sure there's a better way.
(Also, any corrections to tortured terminology, concepts or usage on my part
is appreciated. Whatever I learned a year ago is now fuzzy at best.)
I'm starting with an ugly log generated by my server-side spam blocker. I
use one script to nicely format that log and strip out any entry that is not
a description of a blocked email. The result is a complete list of all
blocked emails, with each record formatted as (in a fixed-width font):
-----------------------------------------------------------------
Date: 04.06.2003 07:42:43
IP: 12.255.39.76
Sender: (e-mail address removed)
Recipient: (e-mail address removed)
Response: 550 5.2.1 Mailbox unavailable.
Reason: SPAMCOP [Spam Source, Various Others -- 127.0.0.2]
Details: Blocked - see
http://spamcop.net/bl.shtml?12.255.39.76
Blacklist:
www.spamcop.net
Lookup:
www.spamcop.net/w3m?action=checkblock&ip=12.255.39.76
-----------------------------------------------------------------
Because of the volume of blocked emails that need to be checked (for
collateral damage), I wrote a second script that further strips out log
records that are, for whatever reason, guaranteed to be spam and don't need
to be manually confirmed.
It's the second script I'm having trouble with. One of the main goals in
writing it was to make it easy to manually add, modify, or delete (within
the script itself) the "definitely spam" descriptions used to cull records
from the log. For that, I use:
my @aDelete =
({
Name => 'open relay',
Marker=> '^ Reason: (NJABL|OSIRUSOFT) \[Open Relay',
Count => "0",
},{
Name => 'china and korea',
Marker=> ' (china|korea) does not seem to care about spam$',
Count => "0",
});
When I process the log, I check each log entry ($sLogRecord) against each
Marker. If it's found, I increment the Count for the Marker. When I'm
done, I use the Name and Count for each Marker to display a summary table of
the results, as well as any log records that survived deletion (and
therefore need to be checked as possible collateral damage):
foreach $sLogRecord ( @aLogRecords )
{
#---------------------------------------------------------------------------
-----------------#
# compare against marker of each record type to be deleted
#---------------------------------------------------------------------------
-----------------#
for( $i = 0; $i <= $#aDelete; $i++ )
{
if( $sLogRecord =~ /$aDelete[$i]->{Marker}/m )
{
$aDelete[$i]->{Count}++;
$sLogRecord = undef;
}
}
}
This may be ugly, but it has worked well and I've been able to easily modify
the entries in @aDelete as needed. The problem I have now is that for the
first time I'd like to delete a record if it doesn't match a particular
Marker. So, I'd like to add an entry to @aDelete such as:
{
Name => 'invalid recipient',
Marker=> '^Recipient: michaelr@encraft\.com)$',
Count => "0",
}
and then rather than:
if( $sLogRecord =~ /$aDelete[$i]->{Marker}/m )
do this instead:
if( $sLogRecord !~ /$aDelete[$i]->{Marker}/m )
It seemed to me that the cleanest way to do this was to include the desired
operator in the @aDelete entry itself:
my @aDelete =
({
Name => 'invalid recipient',
Marker=> '^Recipient: michaelr@encraft\.com)$',
Op => "!~",
Count => "0",
},{
Name => 'open relay',
Marker=> '^ Reason: (NJABL|OSIRUSOFT) \[Open Relay',
Op => "=~",
Count => "0",
},{
Name => 'china and korea',
Marker=> ' (china|korea) does not seem to care about spam$',
Op => "=~",
Count => "0",
});
But I have been unable to find a way to then write:
if( $sLogRecord $aDelete[$i]->{Op} /$aDelete[$i]->{Marker}/m )
that will work in the intended fashion. I have tried every permutation of
eval I can think of.