in reply to concatenate a non-printable character onto an ascii string and inspect the content

You're running into the helpful inclination of Perl to freely interconvert strings and numbers in situations where it seems to make sense (and even sometimes where it doesn't). As | Similarly to what choroba said, what do you think  substr '123456', 0, 1 is?

c:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dump qw(dd); ;; my $string = pack('a*', '123456'); dd $string; ;; print substr $string, 0, 1; printf qq{%02x \n}, substr $string, 0, 1; printf qq{%02x \n}, '1'; ;; foreach my $c (unpack 'C*', $string) { printf '%02x ', $c; } print ''; ;; $string .= qq{\x1c}; dd $string; ;; foreach my $c (unpack 'C*', $string) { printf '%02x ', $c; } " 123456 1 01 01 31 32 33 34 35 36 "123456\34" 31 32 33 34 35 36 1c

Update: Finally noticed that choroba didn't actually say anything about substr, but rather about pack. Still, I think the question about substr is valid.

  • Comment on Re: concatenate a non-printable character onto an ascii string and inspect the content
  • Select or Download Code