*blows dust off perlmonks.org account. I've been away a while, but thought my Perl-fu was up to this rather simple task.

I believe I'm suffering from a rather simple misunderstanding of the /x modifier, and of the {} quantifiers. It's also the first time I've used the named capture buffers, but I'm not sure that matters.

Here's a complete script which should produce a match, so what have I done wrong?

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $vg_details = ' --- Physical volumes --- PV Name /dev/dsk/c14t3d1 PV Name /dev/dsk/c15t3d1 Alternate Link PV Status available Total PE 15997 Free PE 0 Autoswitch On Proactive Polling On '; while($vg_details =~ m/^\s*PV\s+Name\s*(?<pv_name>\S+)\s*$ (^\s*PV\s+Name\s+(?<alt_link>\S+)\s+Alternate\s+Link\s*$){0,20} +# skip them ^\s*PV\s+Status\s+(?<pv_status>\S+)\s*$ ^\s*Total\s+PE\s+(?<total_pe>\S+)\s*$ ^\s*Free\s+PE\s+(?<free_pe>\d+)\s*$ ^\s*Autoswitch\s+(?<autoswitch>\S+)\s*$ ^\s*Proactive\s+Polling\s+(?<proactive_polling>\S+)\s*$/gsmx) { my $pv_name = $+{pv_name}; print "matched $pv_name"; }

The example data is slightly contrived, in that the "Alternate Link" lines are optional (and there may be many). Removing the additional 6 lines below the "PV Name" line in the regex makes it work, so have I completely confused the multi-line comment switch?

Also, I know this is a slightly ludicrous method to process VG data, but I've been handed a big, big list of "vgdisplay -v" output, and this particular edge case is failing. I've reduced it to this minimal example and my eyes still can't spot what's wrong. What silly mistake am I making?


davis


In reply to Regular expression quantifiers and the /gsmx modifiers by davis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.