I'm trying to parse a very general list of parameters. The parameters may be real numbers, quoted text strings, or bracketed sets of such parameters, in any order. Parameters are comma and optional whitespace separated. Balanced extract_multiple looked like what I wanted, and it mostly works, but fails when it gets a real number field or empty field.
It seems that the regexp match is not working as I expected and causing it to think its done.
Here's the code and results:
print "ps before=$param_string\n";
my @ef = (extract_multiple($param_string,
[
sub { extract_delimited($_[0]) },
sub { extract_bracketed($_[0]) },
sub { extract_variable($_[0]) },
qr/([^,]+)(.*)/,
],
undef,1));
print "extracted=@ef\n\n";
Results:
ps before=0.0, 0.0, 0.0, @inches, 0.0, 0.0, [0.0,0.0,'PI$pxtr19i']
extracted=0.0
ps before=0.0,0.0,0.0,@inches,0.0,0.0,[0.0,0.0,'PI$pxtr19i']
extracted=0.0
ps before= "TERMINAL_DRILL_SIZE", "", , @scale , , [0.034, 0.0]
extracted="TERMINAL_DRILL_SIZE" ""
If I remove the regexp match like this:
my @ef = (extract_multiple($param_string,
[
sub { extract_delimited($_[0]) },
sub { extract_bracketed($_[0]) },
sub { extract_variable($_[0]) },
#qr/([^,]+)(.*)/,
],
undef,1));
then the results are:
ps before=0.0, 0.0, 0.0, @inches, 0.0, 0.0, [0.0,0.0,'PI$pxtr19i']
extracted=@inches [0.0,0.0,'PI$pxtr19i']
ps before=0.0,0.0,0.0,@inches,0.0,0.0,[0.0,0.0,'PI$pxtr19i']
extracted=@inches [0.0,0.0,'PI$pxtr19i']
ps before= "TERMINAL_DRILL_SIZE", "", , @scale , , [0.034, 0.0]
extracted="TERMINAL_DRILL_SIZE" "" @scale [0.034, 0.0]
I've patterned this after the example in the docs of parsing CSV text. Any clues why the regexp portion does not seem to do what the docs say?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.