Welcome to the Monastery | |
PerlMonks |
Re: serialise/unserialising data structuresby castaway (Parson) |
on May 30, 2005 at 11:06 UTC ( [id://461757]=note: print w/replies, xml ) | Need Help?? |
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.
In Section
Code Catacombs
|
|