if (/.*simscan~\[\d+\]~([\w|\s]+).*?~(\d+\.\d+)s~.*?~(.*?)~(.*?)~(.*)/) {
-------------------------^^^^^^^^^^
This captures the "result", but with a trailing space. You may want to let the capturing parentheses be followed by \s to prevent that.

                $result   = $1 if $1;
                $scantime = $2 if $2;
                $ip       = $3 if $3;
                $from     = $4 if $4;
                $to       = $5 if $5;

The statement modifiers seem redundant to me.

I don't grasp what you mean, either by the "captures the result" statement, or the modifier statement. I thought that the [\w|\s]+ was 'word or space in any quantity', which would capture either:

"CLEAN"

or

"SPAM REJECT"

Would you please re-write the statement in the context you meant?

Did you consider using split() ?

...actually, no. Now that I think about it, that is how I do almost all other work that is like this.

To be honest, I was following a similar statement in another script that I thought I'd try my hand at custom regex with. I'm finding it exceptionally tedious and error prone. As I've been going through testing, I can't envision myself writing a regex that I can't see a potential to fail for :)

while (<LOG>) {
    chomp;
    my ($result, $scantime, $ip, $from, $to)
      = ( split /~/ )[2,3,5..7] or next;

    $result =~ s/\s+\(.+//;
    chop $scantime;

I don't know why this flew right by me today. Thanks for the feedback.

I'm now off to write this in, with some checking so that my $ip lines up with an IP, and not with a piece of a subject line where someone threw in a rogue ~. (The delimiter is mine, I hacked Simscan to output that as it's delimiter for other custom reasons).

Thanks Gunnar,

Steve








--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to