Try this out.
use strict; use warnings; # See perlvar for why $/ = "" causes $record to contain your entire re +cord at once. The point is to read your data record-at-a-time instead + of line-at-a-time. local $/ = ""; while ( my $record = <DATA> ) { # See perlre for why (.+) fetches everything on the same line as t +he text being matched but doesn't continue onto the next line. Rememb +er, $record is a multi-line string. my ( $pc_name ) = $record =~ /interface (.+)/; my ( $switch_name ) = $record =~ /switchport description (.+)/; print "$pc_name: $switch_name\n"; }
In reply to Re: RegEx Blues
by diotalevi
in thread RegEx Blues
by blackadder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |