Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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
Replies are listed 'Best First'.
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.
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


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


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (13)
As of 2015-10-06 18:58 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (158 votes), past polls