Hi all. I have a "really long string" with many parts to it (something like an IMAP response that needs to be manually processed). So it has sections like:

FLAGS (\Seen) UID 42 RFC822.TEXT {234565} this is a bunch of string data, but it also contains some binary data...it's not actually IMAP code, it's an internal app that works similarly, but a lot more people are more familiar with IMAP... ..snip.. a lot more string RFC822.SIZE 234565 INTERNALDATE " 21 FEB 2016 12:23:23 +1000")
So, I need to work through each part of the string, which I am doing just fine. However, when I come to the part "RFC822.TEXT {234565}" I now need to read exactly 234565 from the string. I am processing this with the m//g operator, so each time I call m//g it matches the string from where I left off the last match. So the code I have, to work through the string, because there is a limit to the n-times match of 32766, is the following:
while( $sz > 32760 ) { $m =~ /(^.{32760})/g; print $FH $1; $sz -= 32760; } $m =~ /(^.{$sz})/g; print $FH $1;

...except the m/(^.{32760})/g isn't matching, and the string pos() is being reset.

Any ideas why? Your input would be gratefully be accepted, I've been banging away at this with various incarnations for more hours than I care to admit :-(


In reply to Matching n characters with m//g by medium.dave

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.