Perl Monk, Perl Meditation | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
To put the earlier answers in context, the only thing you can send over a socket is bytes. Sockets are file handles, and (system) file handles can only handle streams of bytes. That means you need convert your data into a stream of bytes that contains enough information for the received to reconstruct the data. The process of converting the data to a stream of bytes is called serialization. The process of recreating the data from the stream of bytes is called deserialization. Storable is a module used to serialize arbitrary Perl data structures. I think it produces rather compact strings. pack/unpack basically reinvent the Storable wheel, but can be used to produce custom solution such as something even more compact or something that matches an existing serialization method. Storable is not so good if you need to interface with something other than Perl. That's why JSON was mentioned. It's a well defined format that has been ported to many languages and will handle fairly complex structures. Instead of being compact, it's human readable. XML and YAML also share all those characteristics. One advantage of Storable is that it handles embedding the serialized data in the middle of a data stream natively. In most other cases, you'll need some kind of framing to signal the end of the data structure if you intend to keep using the socket. This is often done by preceding the serialized data with the size in bytes of the serialized data.
In reply to Re: Send an Array of Hash in Socket
by ikegami
|
|