Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to pack() returns an unusable string by syphilis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-23 17:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found