Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Reading (and parsing) a byte stream

by ChemBoy (Priest)
on Mar 05, 2006 at 02:55 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-16 15:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found