http://www.perlmonks.org?node_id=593823


in reply to Getting the ascii number through perl's printf

As jettero says, you must use ord if you want Perl to output an ASCII value. The C idiom you are using doesn't make sense in Perl.

#!/usr/bin/perl use warnings; use strict; print ord('c'), "\n";
The 'c' in your C snippet looks just like the 'c' in your Perl snippet, but they're not the same. In C, as you already know, 'c' is a char, a character constant which can be readily exchanged for its corresponding ASCII value. In Perl, 'c' is a scalar value that is also referred to as a string literal. There is no such thing as a char in Perl, though a string literal can certainly contain only one character. I encourage you to read (and refer back to) perldata. With that out of the way, why did your program spit out a warning and convert your string literal 'c' to 0? Grandfather said that it was because Perl "numified" 'c', and that this is Perl slang which means 'what happens when a scalar is used in is a numeric context'. The following snippet may shed a bit more light, try running it.
#!/usr/bin/perl use warnings; use strict; printf "%d\n", '1234'; # The entire string is an integer printf "%d\n", '12c3'; # printf stops the format conversion at the fi +rst non-integer printf "%d\n", 'c123'; # No characters converted, 0 is returned printf "%d\n", '0c123'; # Conversion stops after first character, 0 is + returned