I would prefer to rely on a module than string-splitting.

We don't need a module to parse the grammar I suggested. The grammar is just that simple. That's the point.

All we're doing is parsing the provided value to separate it into a name and a value. And we know the names can't contains spaces or punctuation (except perhaps _ or -).

This is the same approach curl uses.

curl ... -H 'Header1: ...' -H 'Header2: ...' ...

You could leave out the initial dash if you want (-X 'y'/-X 'y ...').

You could use equal signs instead of spaces if you want (-X 'y'/-X 'y=...').

Whatever. The specifics aren't important and are quite flexible since all you have to do is separate a name (with a very limited set of characters) from the rest.

The solution I presented does not "open a different can of worms". It in fact avoids doing so.


In reply to Re^3: Parsing a command-line string into an array by ikegami
in thread Parsing a command-line string into an array by bliako

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.