Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

pack/unpack specification

by kapper (Chaplain)
on Jul 14, 2000 at 14:29 UTC ( #22527=perlquestion: print w/replies, xml ) Need Help??

kapper has asked for the wisdom of the Perl Monks concerning the following question:

As some might recall, I'm working on a Java-Perl connection package.....

For this project, I'm very interested in the exact specifications for the format used by the pack, unpack functions... I would be very happy if some of you might be able to answer some of the following questions...

  1. Is pack/unpack platform independant? endian independant?(can data packed on a 680x0 be unpacked on an x86 and so forth..)
  2. Is pack/unpack at all standardized (... phew.. how do you spell that?).. in other words, can data packed using one perl engine be unpacked in another?
  3. Is there a specification for the format used by pack/unpack?

Replies are listed 'Best First'.
Re: pack/unpack specification
by c-era (Curate) on Jul 14, 2000 at 14:40 UTC
    I have used pack/unpack several times in working with sockets. I've run the program on win32, solaris, linux, and bsd and not had any problems. Pack/unpack stores the information in an 8-bit binnary stream format. Any characters you pack will have their ascii values packed into one byte. The lengths are predefined (i.e. if you use "C" it pack/unpacks an 8-bit value). There could be a problem if a system thinks a "C" is 16-bit, but when you compile perl it does check for that.
Re: pack/unpack specification
by t0mas (Priest) on Jul 14, 2000 at 14:44 UTC
    You can take a look at perldoc perlport for info on the portability of Numbers endianness and Width and other stuff.

    /brother t0mas
RE: pack/unpack specification
by merlyn (Sage) on Jul 14, 2000 at 18:31 UTC
    The "native" int and float format is endian and machine dependant. The "network" order and the inverse "vax" order are machine independant.

    Or at least, that's what I recall writing some years ago to make that camel-ish thingy.

    -- Randal L. Schwartz, Perl hacker

Re: pack/unpack specification
by Aighearach on Jul 15, 2000 at 06:53 UTC
    The documentation for pack() goes into this is some detail. You should read perldoc -f pack. For example, it says:
    The integer formats `s', `S', `i', `I', `l', and `L' are inherently non-portable between processors and operating systems because they obey the native byteorder and endianness. For example a 4-byte integer 0x12345678 (305419896 decimal) be ordered natively (arranged in and handled by the CPU registers) into bytes as 0x12 0x34 0x56 0x78 # little-endian 0x78 0x56 0x34 0x12 # big-endian Basically, the Intel, Alpha, and VAX CPUs are little-endian, while everybody else, for example Motorola m68k/88k, PPC, Sparc, HP PA, Power, and Cray are big-endian. MIPS can be either: Digital used it in little-endian mode; SGI uses it in big- endian mode.

    And it runs onward, into the sunset...

    Paris Sinclair    |    4a75737420416e6f74686572
    pariss@efn.org    |    205065726c204861636b6572
    I wear my Geek Code on my finger.
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2021-10-19 12:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (76 votes). Check out past polls.

    Notices?