Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: perl pack/unpack optional variable length data

by Anonymous Monk
on Dec 18, 2015 at 08:24 UTC ( [id://1150677]=note: print w/replies, xml ) Need Help??


in reply to perl pack/unpack optional variable length data

How do I use unpack in this case?

In what case?

You use too many words in the description but its still too vague

solution is simple, don't read more bytes than you can process

my( $tag, $length ) = unpack ..., $buffer; $buffer = readThisMany( $fh, $length ); my( $value ) = unpack ..., $buffer;

now if $value needs to be unpacked further, or you need to guess how many more bytes to read into $buffer, or ....

If the protocol/format doesn't follow length/value pattern, the docs must specify what pattern it follows, there must be a pattern, an assumption the original program that produced these bytes followed ... just gotta find out what it is

For example Declaring Hash entries

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-23 10:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found