my $month = qr{(?<month>\w+)}; # ...etc my $re_dn = qr{^$month (\d+) (\d{2}:\d{2}:\d{2}) .*: eth(\d): link dow +n}; my $re_dn = qr{^$month (\d+) (\d{2}:\d{2}:\d{2}) .*: eth(\d): link up, + (\d+)Mbps, ([^,]+), lpa (\w+)};
also consider using the /x modifier for better readability.
if you are concerned about DRY and error avoidance, you can also use a pattern hash and automatically wrap the names later
# sketch, totally untested # define groups my %p = ( month => '\w+', ... ); # wrap named groups later while ( my ($k,$v) = each %p ) { $v = qr{(?<$k>)$v}; } # compose patterns my $re_dn = qr{^$p{month} $p{day} ...};
on a side note: you can also chain elsif to avoid always writing next in every if block
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Re: scan, match and extract
by LanX
in thread scan, match and extract
by seismofish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |