On Aug 18, Octavian Rasnita said:

I want to use regular expressions (or other techniques) to split a data
stream which has the following format:

<size_of_next_body><body><size_of_next_body><body>...

The <size_of_next_body> is a 4 digit number and tells the size of the next
body it should get.

You can roll your own with substr() and what-not, or you can use the unpack() function to do it for you:

  my @chunks = unpack "(A4/A)*", $buffer;

The A4/A means "read four characters and get that many characters"; the (...)* around that means "do this repeatedly.

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to