Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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]
[erix]: my favorit scientist Darwin-reply was a good sly move to keep the chattering going ;)
[erix]: I've drawn several continents into the quicksand if I'm not mistaken

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2017-12-15 13:00 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (432 votes). Check out past polls.