in reply to RegEx Blues
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RegEx Blues
by blackadder (Hermit) on Sep 23, 2005 at 08:16 UTC |