title: Converting grouped hex characters into a bitstring in Perl
body: <p>I have some 256-character strings of hexadecimal characters which represent a sequence of bit flags, and I'm trying to convert them back into a bitstring so I can manipulate them with <code>&amp;</code>, <code>|</code>, <code>vec</code> and the like.  The hex strings are written in integer-wide big-endian groups, such that a group of 8 bytes like <code>"76543210"</code> should translate to the bitstring <code>"\x10\x32\x54\x76"</code>, i.e. the lowest 8 bits are <code>00001000</code>.</p>
  
  <p>The problem is that <code>pack</code>'s "<code>h</code>" format works on one byte of input at a time, rather than 8, so the results from just using it directly won't be in the right order. At the moment I'm doing this:</p>
  
  <pre><code>my $bits = pack("h*", join("", map { scalar reverse $_ } unpack("(A8)*", $hex)));
  </code></pre>
  
  <p>which works, but feels hackish.  It seems like there ought to be a cleaner way, but my <code>pack</code>-fu is not very strong.  Is there a better way to do this translation?</p>