Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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


Comment on Re: Reading (and parsing) a byte stream
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-08-29 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls