If the rule is "no additional modules, please!", maybe the simplest (but, admittedly, very dirty way) is to loop over the individual characters of the string - kind of "good old C style" solution. That way it is easy to memorize whether or nor you are inside a quote. Note that you can easily get an array of the individual characters with split(//,$string).

A second possibility I could think of, would be using split(' ',$string), that means, you first pretend that you are not interested in handling the quotes correctly. This gives you an array of fields (some of them contain maybe only one quote), plus (because of the "magic" first argument to split some empty fields for the white spaces. Now you loop through this list. Whenever an element contains only one quote, you have to join it to the next element having a quote (and if the syntax of your string is correct, that element will also have exactly one quote). If you have in between empty elements, you have to treat them as spaces.

Having said this, I personally would prefer the former solution....

-- 
Ronald Fischer <ynnor@mm.st>

In reply to Re: tokenize a string by rovf
in thread tokenize a string by rhymejerky

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.