http://qs321.pair.com?node_id=11133064

syphilis has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

This post arises from an XY problem (for which I already have a very serviceable, albeit inferior, PQ solution).
The following demo script works fine when I set $template to 'd' or 'd<' or 'd>':
# test.pl use warnings; $template = 'd<'; $nv = 2.4; $p = pack $template, $nv; $s = "'$p'"; system $^X, '-wle', "print unpack('H*', $s);";
You can run that on any recent perl, and, for that given template, it should correctly output 3333333333330340.

The problem arises when I change the template to 'D' or 'D<' or 'D>'.
Of course, with the capitalized "D" templates, we're dealing with long doubles. And if you're running perl-5.32.x or earlier, these "D" templates are disallowed unless perl's nvtype is "long double".
However, if you're running perl-5.34.0, then the "D" templates are allowed irrespective of nvtype, thanks to the wonders of modern insanity.
(It's quite sane that the "D" templates now work on -Dusequadmath builds ... but I'm still aghast that they now also work on perls where nvtype is double.)

So ... if you have one of those permitted perl configurations, and you change the template to one of the 3 permitted "D" forms, you'll see the script fail, with the diagnostic warning:
Can't find string terminator "'" anywhere before EOF at -e line 1.
I wonder why that happens ? Is it because of the embedded NULLs in $p ?
More importantly, how do I get to pass that string $p to the system command so that when the template is set to 'D<' the script successfully outputs the expected (and correct) 9a999999999999990040000000000000 (or 00999999999999990040000000000000 if perl is 5.34.0 && nvtype is double).

I'm hitting the same issue on both Windows 7 and Ubuntu-20.04.

Cheers,
Rob