Re: Regex advice

[email protected] (Gunnar Hjalmarsson)
Newsgroups perl.beginners
Message-ID <[email protected]>
Steve Bertrand wrote:
> 
> 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.

Did you consider using split() ?

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

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

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.