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


in reply to Re: pack() returns an unusable string
in thread pack() returns an unusable string

Guessing is sometimes fine, but the OP gave an entire and complete test script which you can examine and even run. If I make a small modification to the test script given we can test the theory:

# test.pl use warnings; $template = 'd<'; $nv = 2.4; $p = pack $template, $nv; $s = "'$p'"; print ">$s<\n"; system $^X, '-wle', "print unpack('H*', $s);";

prints:

>'333333@'< 3333333333330340

running a 64 bit build of 5.32. Note that there is an ETX character between the final 3 and the @ character, which, when you think about it, is the string that the unpack is showing us so for the success case there is a trailing @ and it isn't swallowing the trailing '.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^3: pack() returns an unusable string
by tybalt89 (Prior) on May 26, 2021 at 23:29 UTC

    OP said error only happens on D<, not d<, which doesn't run on my machine.

    However, here is a number for which the error occurs on 5.32 with d<

    #!/usr/bin/perl -l use strict; use warnings; my $template = 'd<'; my $nv = 2.4; $nv = 4135; # NOTE errors for this number my $p = pack $template, $nv; my $s = "'$p'"; print ">$s<\n"; system $^X, '-wle', "print unpack('H*', $s);";

    Outputs:

    >''@'< Can't find string terminator "'" anywhere before EOF at -e line 1.

    which shows that my guess that the pack produces a single quote character is plausible.

      In blead, it runs with D< and fails with
      Can't find string terminator "'" anywhere before EOF at -e line 1.

      However, when I tried to output

      say join ', ', map ord, split //, $p;
      I got
      0, 152, 153, 153, 153, 153, 153, 153, 0, 64, 0, 0, 0, 0, 0, 0

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]