Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: pack() returns an unusable string

by GrandFather (Saint)
on May 26, 2021 at 22:30 UTC ( #11133097=note: print w/replies, xml ) Need Help??


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]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11133097]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2021-10-22 10:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (85 votes). Check out past polls.

    Notices?