develooper Front page | perl.perl5.porters | Postings from July 2021

Make $) and $( not IOK?

From:
Felipe Gasper
Date:
July 1, 2021 00:48
Subject:
Make $) and $( not IOK?
Message ID:
FB035293-2A79-43A7-A139-758FE47DCC5F@felipegasper.com
Hi all,

	I’ve noted that the fact that these are IOK confuses serializers into doing things like this:

-----
> perl -MSereal -MData::Dumper -e'$) = "3 2"; print "$)\n"; print Dumper( Sereal::decode_sereal( Sereal::encode_sereal( $) ) ) )'
3 2
$VAR1 = 3;
-----

Note that round-tripping $) through Sereal yields 3, not '3 2'. This is because after $)’s magic is set, the resulting SV is both IOK and POK. Since serialization of a number is often more efficient than of a string, serializers will prefer to notate the numeric value instead of the string. In this case, though, that loses valuable information.

	What if, along the lines of what Paul has recently proposed to help serializers achieve reliable string/number typing, $) and $( de-magicked to values that are IOKp, but not IOK? This would allow numeric operations on those values without generating “not a number” warnings, and it would compel Sereal et al. to serialize those values as strings, thus preserving the extra GIDs.

	Thoughts?

-Felipe


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About