Well, you regex is not working, at least not as I'd expect it to work - apart from the fact that the 'Class\n====\n' header is missing. The array @devices gets just the first entry line ('graphics 0 ...'). The reason for this is that the /g modifier on the regex is not matching multiple times because the header is there only once.
So do it in two steps like this:
as far as I can tell this is not a problem with greedy matching. You just expected the /g modifier to dwim more than it does.#!/usr/bin/perl $_ = do {local $/; <DATA>}; s/(Class.+\n=+\n)//; $header = $1; @devices = m/(^\w.+\n(?:\s+.+\n)*)/mg; __DATA__ Class Foo ========= graphics 0 1 graph3 CLAIMED INTERFACE Graphics disk 0 2/0/1.0.0 sdisk CLAIMED DEVICE HP +C2247M1 /dev/dsk/c0t0d0 /dev/rdsk/c0t0d0 ctl 0 2/0/1.7.0 sctl CLAIMED DEVICE Initiato +r /dev/rscsi/c0t7d0
-- Hofmator
In reply to Re: A query on greedy regexps
by Hofmator
in thread A query on greedy regexps
by sch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |