Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: serialise/unserialising data structures

by castaway (Parson)
on May 30, 2005 at 11:06 UTC ( [id://461757]=note: print w/replies, xml ) Need Help??


in reply to serialise/unserialising data structures

Not bad.. I was playing with bdecode/bencode recently (implemented them in elisp, fun) ..

A comment or two: Your code actually only encodes/decodes lists and dictionaries, it will completely ignore single values, eg it wont parse "4:spam" at all. You also have the string/integer parsing code in there twice. You can solve both of these in one go by making the main if (substr(${$dictref},0,1) eq "d") { statement also do strings and integers, and recursing when encountering these inside the dictionary/hash, instead of parsing them on the spot.

Ditto the encoding.

Pretty nifty all the same :)

C.

Replies are listed 'Best First'.
Re^2: serialise/unserialising data structures
by monoxide (Beadle) on May 30, 2005 at 11:30 UTC
    The main reason for not doing strings/integers was the idea that 98% of the things that you would want to do would be some sort of list/array not a single value, but i can see the value in doing it that way... also something that is not "ideal" is the fact that it will erase the string you pass to it in the decode function, returning the hash/array, but deleting everything out of the scalar ref that you pass to it. ie.
    bDecode(\$str); # $str is now == ''
    Any suggestions on fixing this would be appreciated.

    NOTE: I implemented castaway's suggestions. Very nice idea there :).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-23 07:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found