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.
In reply to Re: How can i catch strings matching a regex across multiple lines?
by Anonymous Monk
in thread How can i catch strings matching a regex across multiple lines?
by babelfish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |