in reply to Re^3: extracting a substring from a string - multiple variables
in thread extracting a substring from a string - multiple variables

seems like graff was faster again ;)
I did like your approach though!
I'm not quite sure if (in your solution) $binary is known - in my case I'm handling POSTed data, where $length is declared in the data, and $binary just sits between the <file/> tags.
Still; if $length and $binary could be extracted, unpack sounds more logical to me.
  • Comment on Re^4: extracting a substring from a string - multiple variables

Replies are listed 'Best First'.
Re^5: extracting a substring from a string - multiple variables
by mwah (Hermit) on Oct 28, 2007 at 08:39 UTC
    walinsky
    in my case I'm handling POSTed data, where $length is declared in the data, and $binary just sits between the <file/> tags.

    If thats so you *definitely* can't use any approach other than blindly extracting a byte sequence of given length (as in Example 2) because the data *might* at some point contain the sequence  \x00€µ</file>³á>>~ which would break your program otherwise (if you'd use the regex like ... =~m{<file>.*?</file>} ...).

    Regards

    mwa