I'm still looking for wisdom on why the reg expr match terminates extract_multiple. But I have created a workaround for my initial goal of parsing a generalized list of parameters. I offer it here for your amusement:
my @ef = (extract_multiple($param_string, [ sub { extract_delimited($_[0]) }, sub { extract_bracketed($_[0]) }, sub { extract_variable($_[0]) }, ], undef,0)); my ($extracted, @fields, $field, @subfields); foreach $extracted (@ef) { if ($extracted ne ",") { if ($extracted =~ /^["'`\[\(\$\@\%]/ ) { push(@fields, $extracted); } else { # If this is not the first field, remove any leading # spaces and a comma. If it was the very first field, # then the first comma is significant. if (@fields) { ($extracted) = ($extracted =~ /\s*,?(.*)/); } @subfields = split(/,/, $extracted); # Split on comma foreach $field (@subfields) { ($field) = ($field =~ /([^\s]+)/); # Keep non-space push(@fields, $field); } } } }
Note the use of extract_multiple to first separate out all the delimited (quoted, etc), bracketed, and variable-like fields. Also, note that I set the last parameter to 0 so that it will return all the unmatched substrings. These substrings need to be further processed to split them up.

At this point I loop thru the extracted fields, pushing them directly on the final @fields list if they were "balanced" text. If they were the unmatched substrings then we will split them on commas, and ignore any whitespace.

To eliminate an extra null param at the beginning of an unmatched substring, I first eat a leading comma (and optional space), but only if this is not the very first parameter in the whole list (you need that one in case there really was a leading null param).


In reply to Re: Text::Balanced extract_multiple does not return all values by JohnRuf
in thread Text::Balanced extract_multiple does not return all values by JohnRuf

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.