If your string is in $expect_data, try the following:
while ($expect_data =~ /(\d{1,3})/g) { my $next_chunk = $1; # Validate here }
The idea of this is quite simple. In Locate char in a string I gave an explanation of the principle from which you can loop over a match. All that is left is to explain the match. \d, of course, is a digit. \d{1,3} is short-hand for saying "1-3 digits". By default it matches as much as possible, so that will grab 3 digits at a time. I assume that you would want the final digit or two to be grabbed as well. Putting parens around it causes the matched section to be popped into a variable, $1.

If this sounds like a bit much, well I just threw a lot at you. Try some examples though and it shouldn't take long to get a sense how it works. What you are looking for is anything on "regular expressions". Any introductory book has material on this, and the standard reference that I have to recommend is Mastering Regular Expressions by Friedl.

As always, /tell me if you have problems figuring out how to use this advice.


In reply to Re: Sorting by tilly
in thread Parsing a string for sorting by grasshopper

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.