in reply to scan, match and extract
use strict; use warnings; my $time_stamp = qr{^(\w+) (\d+) (\d{2}:\d{2}:\d{2})}; while (<DATA>) { next if !(my($mon, $day, $time) = /$time_stamp/); next if !(my($interface, $updown) = $' =~ /.*:\seth(\d): link (up| +down)/); if ( $updown eq 'down' ) { #... # Process down print $time, "\n"; } else { my( $rate, $duplex, $lpa ) = $' =~ /,(\d+)Mbps, ([^,]+), lpa ( +\w+)/; next if !defined($lpa); # Invalid 'up' probably never happens. #... # Process up print $lpa, "\n"; } } __DATA__ May 03 10:15:21 some text: eth3: link down May 04 10:16:23 some text: eth3: link up,562Mbps, foos, lpa fum no time
UPDATE: Refer to @LAST_MATCH_START and @LAST_MATCH_END for documentation on $'.
|
|---|