here is what I am doing:
I am taking a multidimensional array, or rather, an array of hashes and trying to pass it into a python script from my perl script. Currently I am converting it to json, and then passing the json string as a literal string into the python script as a parameter.
The array of hashes looks like the following example:
%HoH = (
id10001 => {
lat => "180",
long => "-180",
},
id10002 => {
lat => "180",
long => "-180",
},
id10003 => {
lat => "180",
long => "-180",
}
);
which i then inside of my perl script, turn into a json string:
{
"id10001": { "lat": "180", "lon": "-180" },
"id10002": { "lat": "180", "lon": "-180" },
"id10003": { "lat": "180", "lon": "-180" },
}
which then is passed into a python script. The python script decodes the json string back into the original constructed array structure.
Is there a better way to pass arrays, or multidimensional arrays from a perl script to a python scrip?
thank you in advance for your help
No, serialization is the only way to pass data through plain character buffer (such as command line arguments, file or whatever) by its very definition. As long as specific serialization format – JSON is this case – naturally covers language-specific structures, you’re all set.
If you so wish you can experiment with benchmarking libraries for serialization formats available to both Perl and Python to see which will be faster in your case, but at least Perl’s XS implementation of JSON is known to be very fast and routinely beat in speed other available serializers.