156

Input/Output
The Pack Function

  • The pack() function packs Perl data into a native binary format

      $packed = pack( TEMPLATE, LIST );

  • Special template characters specify how to encode the data

      a, A, b, B, h, H, c, C, s, S, i, I, l, L, n, N, f, d, p, x, X, @, u

  • A few simple examples

      $packed = pack( "ccc", 65, 66, 67 );
      # $packed is now "ABC"

      $packed = pack( "f2", "3.1415", $e );
      # Pack two floats in native format