Front page | perl.perl5.porters |
Postings from February 2017
Question about the inner workings of "storable".
Thread Next
From:
Michel Albert
Date:
February 9, 2017 19:32
Subject:
Question about the inner workings of "storable".
Message ID:
CAM8bmgAUGy530sBABypUgRHoHjz96UE=Rg_1msr=_CjXu7cUXA@mail.gmail.com
Hi,
I am currently working on a Python port of "storable" (in order to
deserialise a storable file into a Python data structure).
The module in question is: https://github.com/exhuma/python-storable
I have forked it off from the original from CowboyTim/python-storable as
this seems abandoned. I have tried to contact the author, but have not
heard back from him in over a week. There are a couple of things that are
not 100% clear to me as I'm not very proficient in Perl. I would like to
get a deeper understanding of a few things before proceeding with
modifications in the Python module.
To my first question I probably already know the answer, but I prefer to
have confirmation: *Should strings in Perl (scalars?) be considered to be
in the encoding of the source .pl file?* Python distinguishes between bytes
and text (unicode) literals, and when loading the ".storable" file this
should be taken into account. As an example, the tests of the given Python
module use the following Perl hash in it's unit-tests:
save_sample('simple_hash01', {aa => 'bb'});
Both "aa" and "bb" seem to be stored as a scalars (bytes?), so without
knowing the encoding of the .pl file, I can only deserialize them as raw
bytes. Is this correct or can one assume a fixed encoding? Like ASCII maybe?
*The second question: Should numerical keys in hashes be deserialized as
numericals as well?* The example from the existing code stores the
following:
save_sample('integer_hash', {44556677 => 'a', 556677 => 'b'});
but when I use the existing code from the python library, the keys are
decoded as bytes instead of integers. Looking back at my first question I
wonder if both are not related? In which case, it cannot be safely decoded.
Or, to ask differently: Is the following possible in Perl, and if yes, how
are the two keys distinguished from each other?
save_sample('mixed_hash', {123 => 'a', '123' => 'b'});
*The third question: How does Perl know to store values as UTF-8?* I came
across the following snippet in test.pl:
# utf-8 test
my $a = "\x{263A}";
save_sample('utf8test01', \$a);
"storable.py" contains two decoding functions related to UTF-8:
*SX_UTF8STR* and
* SX_LUTF8STR*. How does Perl-storable know that the value above has to be
flagged as UTF-8 and not as plain scalar?
Best regards,
Mich.
Thread Next
-
Question about the inner workings of "storable".
by Michel Albert