Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: concatenate a non-printable character onto an ascii string and inspect the content

by AnomalousMonk (Chancellor)
on Sep 20, 2017 at 17:14 UTC ( #1199768=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1199768]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2017-10-20 04:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (258 votes). Check out past polls.

    Notices?