From: Octavian Rasnita [mailto:[EMAIL PROTECTED] 
Sent: Thursday, August 18, 2005 8:04 AM
To: beginners perl
Subject: splitting data stream

Hi,

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.

Thank you very much.

Teddy


It's not clear from your note exactly what the data stream looks like... 
Is it delimited between fields? Are the fields in a "record" and is the
record delimited? Can you "dump" some of the data and include it in a post?

But given the above...

perl -e'
$a=q{0010testtest1X0005testX0001A0003BBX0006CCCCCX};
while (length($a)) {
        $size=substr($a,0,4);
        $body[$i]=substr($a,4,$size);
        $a=substr($a,4+$size);
        $i++
        }
print "$_\n" foreach (@body);
'

DEV,SUN2>
testtest1X
testX
A
BBX
CCCCCX
DEV,SUN2>
jwm

-- 
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