Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Reading (and parsing) a byte stream

by ChemBoy (Priest)
on Mar 05, 2006 at 02:55 UTC ( #534552=note: print w/replies, xml ) Need Help??

in reply to Reading (and parsing) a byte stream

I don't see anything on CPAN that would solve this problem, though HTTP::Handle might make it a bit easier. I do see a couple of things that might be your problem, though. First off, do you want byte #4, or the byte at index 4? You've got the latter at the moment (from bytes::substr($buf,4,1,undef)), which is of course what most people would call byte #5.

I think that's probably the issue you're looking at, because ord usually does what you expect in this case, but if you're parsing binary data, you really should be looking at unpack, which is specifically designed for this task. Assuming you weren't doing anything with the rest of the string, the invocation in this case would be

my $byteval = unpack "x3C", $buf;

Good luck!

If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://534552]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-08-07 23:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found