pack and unpack functions.

" />
x
Loading
 Loading
Hello, Guest | Login | Register

Packing It In

Take a look at Perl’s confusing, but important pack and unpack functions.

The other authors of the wildly popular Learning Perl book and I dropped a few things between the second and third editions of the tome, simply because we wanted to make room for a few more relevant topics. As Perl has matured, Perl users migrated from being primarily system administrators to traditional developers, authoring complete mission-critical applications, such as some of the code behind many of the websites that you visit frequent. One of the sections that didn’t make the cut was the section on the confusing, but important pack and unpack functions. This month, let’s take a look at this small corner of the Perl universe.

Bits and Pieces

The pack function turns Perl-managable data (numbers and strings) into a sequence of bits that might make sense to some external application. unpack generally goes in the other direction, taking a bag-of-bits from some hostile, real-world interface, and turning the parade of one’s and zeroes into nice strings and numbers for further processing.
The number of options for pack and unpack is dizzying. In fact, as I was researching this article, I realized that I hadn’t read the related documentation for a few Perl releases, and it seems that they’ve snuck in about twice as many features as when I last looked. Too bad a pack format isn’t quite Turing-complete, although I’m happy they aren’t self-aware, as regular expressions seem to have become.
The easiest way to get into how…

Please log in to view this content.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. Helpful Tools for Software Developers
  2. The Github Hall of Fame
  3. Book'em, Github.
  4. This Week on Github: Stupid Ruby Tricks
  5. A Veritable Scatter Shot!
Follow Linux Magazine
Rackspace