Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- PERL 4.0 Reference Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

     unpack(TEMPLATE,EXPR)

             Unpack does the reverse of pack: it takes  a  string
             representing  a structure and expands it out into an
             array value,  returning  the  array  value.   (In  a
             scalar  context,  it  merely returns the first value
             produced.)  The TEMPLATE has the same format  as  in
             the  pack  function.   Here's a subroutine that does
             substring:

                  sub substr {
                       local($what,$where,$howmuch) = @_;
                       unpack("x$where a$howmuch", $what);
                  }

             and then there's

                  sub ord { unpack("c",$_[0]); }

             In addition, you may prefix a field with a %<number>
             to indicate that you want a <number>-bit checksum of
             the items instead of the items themselves.   Default
             is  a  16-bit  checksum.  For example, the following
             computes the same number as the System  V  sum  pro-
             gram:

                  while (<>) {
                      $checksum += unpack("%16C*", $_);
                  }
                  $checksum %= 65536;

See Also: pack

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson