in reply to How can i catch strings matching a regex across multiple lines?
The problem is this line
my ($id) = ( $_ =~ /Logical device ID=(\w+)/ );
If you add
right afterwards, and run your program, you can see that $id gets reinitialized upon each iteration of the loop (with each new line read)use Data::Dump; dd { line => $_, id => $id };
You want this
my $id; while.... { $id = $1 if /Logical device ID=(\w+)/ ; dd { line => $_, id => $id }; }
See Tutorials: Variable Scoping in Perl: the basics, Coping with Scoping , Mini-Tutorial: Perl's Memory Management, Lexical scoping like a fox, Basic debugging checklist , brian's Guide to Solving Any Perl Problem
Also, see Parse::Report - parse Perl format-ed reports.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can i catch strings matching a regex across multiple lines?
by NetWallah (Canon) on Jun 30, 2012 at 23:14 UTC | |
by aaron_baugher (Curate) on Jun 30, 2012 at 23:42 UTC | |
|
Re^2: How can i catch strings matching a regex across multiple lines?
by CountZero (Bishop) on Jul 01, 2012 at 11:15 UTC |