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

passing data structures from java to perl

by daverave (Scribe)
on Jul 28, 2010 at 19:02 UTC ( #851764=perlquestion: print w/ replies, xml ) Need Help??
daverave has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I would like to pass some data structures from java to perl. In perl, this should basically be a hash where the keys are strings and each value is either a string, a hash or a hash of hashes. Is there a way to dump\write data from java that can be easily parsed by perl?

Comment on passing data structures from java to perl
Re: passing data structures from java to perl
by almut (Canon) on Jul 28, 2010 at 19:22 UTC

    You could serialize the data structure to JSON, and then deserialize it from Perl using JSON.

      Or XML as well, using XML::Simple from cpan.
      Thanks!
Re: passing data structures from java to perl
by exussum0 (Vicar) on Jul 28, 2010 at 20:04 UTC
    If you use JSON or XML, be mindful of your character sets. Java IS UTF-16, which covers ASCII. If you're doing it outside of ASCII, be mindful.

    XML has character encoding, to its advantage but takes more work to rig up.

      It should be no real problem to have Java create UTF-8 encoded files/streams (both JSON and XML), and JSON can read UTF-8 data just fine... (Similarly for XML)

        Agreed. As long as no UTF-16 chars are used, which is really easy to do in java since strings are all UTF-16, it's all gravy.

        Java strings are UTF-16

        A good XML writer that prevents you from going outside of the declared format will protect you from future mistakes. Down side is the extra effort in using some XML api over others. JSON is usually gravy in all languages.

        Gravy.. mmmm...

Re: passing data structures from java to perl
by trwww (Priest) on Jul 29, 2010 at 02:01 UTC

    Hello,

    Depending on your requirements, I'd probably just use Inline::Java and let it take care of the serialization.

    regards,

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://851764]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-12-25 13:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls