Mu. You started with the wrong package.
Perl does not have a meaningful type system that distinguishes between numbers and strings. Any given value can be both. It cannot be determined using only the Perl language, regardless of whether a given value is considered a number only (although you can use modules like Devel::Peek ). It is completely impossible to find out what type the given value was originally from.
my $x = 1;
In addition, in the hash map ("dictionary"), the key type is always coerced to the string. In arrays, the key is always bound to an integer. Other types can only be faked.
This is great for text analysis, but, of course, is an endless pain in serializing the data structure. JSON is ideal for Perl data structures, so I suggest you stick with this (or YAML, as it is a superset of JSON) to protect yourself from the misconception that serialization may output information that may not exist.
What will we take from this?
If interop is important, refrain from using creative dictionary types in Python.
You can always encode type information in serialization if it is really important (hint: maybe it is not): {"type":"interger dict", "data":{"1":"foo","2":"bar"}}
It would also be premature to reject XML as too slow. See this recent article , although I disagree with these methods and am limited to JS (last week HN thread for perspective).
If it's native, it will probably be fast enough, so obviously don't use pure versions of Perl or pure-Python. This is also true for JSON- and YAML- and some -parersers.
source share