Welcome to the Monastery | |
PerlMonks |
pack 'c',... -vs.- pack 'C',... was: Re: Re: Re: PayPal Advice Soughtby ariels (Curate) |
on Jul 08, 2001 at 01:07 UTC ( [id://94768]=note: print w/replies, xml ) | Need Help?? |
epoptai's right -- there's no difference between
pack 'c',$number and
pack 'C',$number, ever. There
is a difference when unpacking, of course.
What the translations 'c' and 'C' do when packing is to translate an integer to a corresponding character value. Your character values are most likely single-byte numbers. Each corresponds to a specific modulus of integers. In particular, the two most popular ways to assign representative integer values to the 256 bytes are 0..255 ("unsigned char") and -128..127 ("signed char"). But of course any integer value is congruent (modulo 256) to exactly one byte value, whichever of the 2 ranges you pick. So any integer has a unique translation to a byte. The reverse direction (unpack 'c',$str) is less single-valued: for instance, unpack 'C',(pack 'C',-1) == 255. Here unpack has to chose a specific range from which to pick an integer representing the byte value, and the two letter codes make a difference. The same thing occurs for the other signed/unsigned letters for integer conversions in pack/unpack.
In Section
Seekers of Perl Wisdom
|
|