Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Answer: What's the difference between chr() and pack('C', hex($1))?

by Fastolfe (Vicar)
on Oct 18, 2000 at 22:55 UTC ( #37395=categorized answer: print w/replies, xml ) Need Help??

Q&A > strings > What's the difference between chr() and pack('C',hex($1))? - Answer contributed by Fastolfe

There is a subtle difference that may bite you. chr works on characters while pack "C" works on bytes. With a standard ASCII character set, these are indistinguishable under most circumstances, but if you're using unicode (see perlunicode) data in later versions of Perl, chr and ord behave differently than their pack/unpack counterparts. pack/unpack will still work with individual bytes while chr/ord will actually deal with the full unicode character, which may be longer than 1 byte.

  • Comment on Answer: What's the difference between chr() and pack('C', hex($1))?
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
1nickt is installing all Perl versions so as to be able to send test reports to CPANTS ...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2017-09-19 17:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (226 votes). Check out past polls.

    Notices?