views:

81

answers:

3

I just want to transfer (send or receive) a hash from client to server.

Can you tell me which is a preferable way in Perl or can you suggest any CPAN modules?

A: 

the socket module?

ghostdog74
Im ok with the basic socket communication , but the problem is I want to transfer a hash from client to server
abubacker
+11  A: 

You can encode the hash using JSON on the client side and send the encoded string to the server.

Then, decode the received string (again using JSON) on the server side and you can get back your hash.

JSON::Any works great :-) , Thank u
abubacker
cool..! ur welcome!
+2  A: 

See Storable and Data::Dumper. Both are core modules.

planetp
Both cannot be suitable for transfering isn't it
abubacker
I wonder – what makes you think so? Even though I also would prefer JSON, `Storable::nstore()`/`retrieve()` and `Data::Dumper::Dumper()`/`eval` work just fine, the concept is no different.
daxim
JSON is a standard and therefore protects you from unexpected changes in the hash representation messing up your application. To avoid that using DataDumper, you need to always use the exact version on both ends.Also, using JSON you can easily exchange either the client or the server for a non-Perl solution.
Thomas Kappler
Storable wins if you have Perl at both ends and need a compact representation. Otherwise, YAML or JSON is the way to go for the reasons Thomas mentions. I would not use Data::Dumper--the requirement to **execute arbitrary input as code** is a non-starter.
daotoad
Incase of Storable we must give the Socket filehandler as an inputfoe ex : $text = Storable::fd_retrieve($client_file_handler);so when the client closes the function throws an error and the server program exits . since I dont want a server to be closed abrubptly. since it needs to handle more than one client at the same time.
abubacker
JSON is really a useful module which is used to complete my requirement , thanks to every one for suggesting that. :-)
abubacker
Thomas Kappler: It is ridiculous to argue from the assumption that Perl data serialisation (the "Dump" format not backed by a standard) might change, as it's been around for several the lifetime of JSON and has a stupendous installed user base because it's directly a part of the language and therefore compatibility must not be risked. Thus, your claim about needing the same version of D::D at both ends is plain false. – It seems lately on SO if one just makes bold enough statements people are happy to upvote it immediately without thinking or verifying. ☹
daxim