We don't bite newbies here... much | |
PerlMonks |
Multiple line records from a command stringby Preceptor (Deacon) |
on Feb 23, 2010 at 14:50 UTC ( [id://824873]=perlquestion: print w/replies, xml ) | Need Help?? |
Preceptor has asked for the wisdom of the Perl Monks concerning the following question:
I'm probably being a little daft, but I'm sort of trying to get my head around the most elegant way to accomplish this, rather than one that 'just works'. If I run a particular command I (long) list of entries, that look something like: This pattern is repeated a lot of times, once for each volume in my storage array. What I'd really like to be able to do, is define a multi-line regexp, that matches 3 or 4 lines out of it (Device Symmetrix Name, Symmetrix ID, any one of the capacity entries, and the state of the SCSI-3 Persistent Reserve:) and then allows me to do some manner of 'foreach loop'. So far, I've figured I can just do a line by line 'foreach', and set variables based on matching particular lines: That sort of thing. But that seems ... well, just rather inelegant really, when I'm pretty sure I can do multi-line regexps. I just can't quite get my head around how to turn at multi-line RE into 'something useful' for a 'foreach' loop, with multiple values. I've found the 'm' flag on the pattern match, and can knock together something that matches a single record. Well, approximately - that's not quite what I want to do, as the greedy matches will eat the intervening chunks of the command output. But essentially, I want to do that 'per record'. Given the output of this particular command generates around 400Mb, I may end up dumping it to a file first.
Back to
Seekers of Perl Wisdom
|
|