Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: pack peculiarity

by pg (Canon)
on Dec 27, 2003 at 02:23 UTC ( [id://317152]=note: print w/replies, xml ) Need Help??


in reply to pack peculiarity

I made a little piece of code to help you understanding what's going on:

$number = 1145258561; print pack( "l", $number ), "\n"; do { print chr($number % 0x100); $number = $number >> 8; } until (!$number);

Replies are listed 'Best First'.
Re: Re: pack peculiarity
by sgifford (Prior) on Dec 27, 2003 at 06:58 UTC
    To clarify a little bit (I hope), Perl's strings are a string of bytes, which may or may not be a string of printable characters. When Perl is asked to print a string, it just outputs all of the bytes in the string, one after the other. In this case, the bytes are 0x41 0x42 0x43 0x44, which happen to be the ASCII character codes for ABCD.

    Update: As pg mentions below, this terminology might be wrong in the face of Unicode. If, for the sake of this example, you temporarily pretend Unicode doesn't exist, hopefully this comment will still shed some additional light. :-)

      I like the infomation you added. But you may want to reconsider your statement that "Perl's strings are a string of bytes", as there are actually two semantics: bytes and characters, especially when you have unicode in mind. (Obviously the actual storage is a stream of octets, but there are two different semantics to interpret. There is a very subtle difference in the concept of octet and byte, and probably you noticed that those two words are used very carefully nowadays in all kinds of standards.)

      I know what you meant, just thought that that pariticular statement might be a little bit too generalized.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://317152]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-05-21 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found