Here is an SSCCE showing the storage of the capture groups in an array. Then you don't need a list of numbered scalars.
use strict; use warnings; use Test::More tests => 2; my $re_dn = qr{^(\w+) (\d+) (\d{2}:\d{2}:\d{2}) .*: eth(\d): link down +}; my $re_up = qr{^(\w+) (\d+) (\d{2}:\d{2}:\d{2}) .*: eth(\d): link up, +(\d+)Mbps, ([^,]+), lpa (\w+)}; my @log = ( 'May 19 13:58:01 foo: eth0: link down', 'May 19 13:58:11 foo: eth0: link up, 100Mbps, bar, lpa quux' ); for (@log) { my @matches; if (@matches = /$re_dn/) { my ( $mon, $day, $time, $interface ) = @matches; is $time, '13:58:01'; next; } if (@matches = /$re_up/) { my ( $mon, $day, $time, $interface, $rate, $duplex, $lpa ) = @ +matches; is $time, '13:58:11'; next; } }
Increase the number of tests as you wish to confirm that all the groups are returning the correct results.
🦛
In reply to Re: scan, match and extract
by hippo
in thread scan, match and extract
by seismofish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |