Replying to myself, mwah and graff

I'm handling POSTed data, actually I'm reverse engineering .Mac services. This is why I'm not afraid the 'length' information can't be trusted; programmers from Cupertino wouldn't fool themselves _that_ much.
Also, as far as I've seen, there's never been more than 1 <file></file> pair. It would just have been the cherry on the cake to take that chance out.
As
if ( $indata =~ s{<file fiop="([^"]+)" length="([^"]+)"/>(.*?)</file>} +{}s ) { ( $fiop, $fileLength, $fileData ) = ( $1, $2, $3 );

works (for now), but I definitely want to take out the chance that the binary data contains </file>, I just'd like to optimize the regex.
I _do_ know it can be done with substr, but (knowing -but not completeley understanding- the power of regex) I just wondered if a back-referencing to length within the regex would/could be possible.
Is something like:
if ( $indata =~ s{<file fiop="([^"]+)" length="([^"]+)"/>(.{$2})</file +>}{}s ) { ( $fiop, $fileLength, $fileData ) = ( $1, $2, $3 );
possible ?

update:
As regex is limited in matching to a given (64k - or so) length; we decided to assume there's only 1 occurence of a <file/> node; we can match greedy:
if ( $indata =~ s{<file fiop="([^"]+)" length="([^"]+)"/>(.*)</file>}{ +}s ) { ( $fiop, $fileLength, $fileData ) = ( $1, $2, $3 );
(matching the final occurence of </file>)

In reply to Re^7: extracting a substring from a string - multiple variables by walinsky
in thread extracting a substring from a string - multiple variables by walinsky

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.