in reply to Flipping the Sign Bit in pack()'ed Value

You used strict. Very good. But you didn't use warnings. Why?

When I run the code with warnings, I'm getting

Argument "B" isn't numeric in numeric bitwise xor (^) at 1.pl line 10.

But even using

use feature qw( bitwise );
and changing the xor line to
my $stoval = "$pckval" ^. 0x80;
doesn't fix it according to your expectations:
$stoval = "B" ^. 0x80; # $stoval = [s28] - Expecting [194] $stohex = "0x" . (unpack 'H16', "s28"); # $stohex = [0x733238] - Ex +pecting [0xc2]

You need to use a character on the right hand side of the xor, too.

my $stoval = $pckval ^ "\x80"; # or my $stoval = $pckval ^ chr 0x80; # or my $stoval = $pckval ^ pack 'C', 0x80; # ...

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

Replies are listed 'Best First'.
Re^2: Flipping the Sign Bit in pack()'ed Value
by marinersk (Priest) on Jun 09, 2025 at 13:30 UTC

    choroba wrote:

    You used strict. Very good. But you didn't use warnings. Why?

    Long list of reasons. Short answer: Bad habits, I was in a hurry, and I'm arrogant.

    And that bit me: May the lesson stick well this time

    You need to use a character on the right hand side of the xor, too.

    Thank you. (My instinct was suggesting a typecasting problem; I probably should have followed up on that before posting. Ah, well.)