Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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
Node Status?
node history
Node Type: note [id://534552]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2018-03-19 02:54 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (232 votes). Check out past polls.