SPUG: Math Genius

Andrew Sweger andrew at sweger.net
Thu Jul 25 20:51:48 CDT 2002

Uhh, yeah. I'm supposedly writing a tutorial on the use of the
pack()/unpack() functions in Perl. But I'm taking my sweet time about it
(I conveniently forget everything I know about it when I'm not using it).

There is a new tutorial on pack()/unpack() included in the Perl 5.8.0
release written by Simon Cozens (who I'm told looks suspiciously like
former ESPUG Emperor Erwin) and Wolfgang Laun. If you haven't made that
particular jump (to 5.8), I have made it available in HTML format:


In response to your email (finally), I'm not sure I understand: You want
to pack (convert) a hexadecimal (string) into an alphanumeric (string)? Or
do you need to convert a hexadecimal string into its corresponding byte
representation (which is what one normally does with pack())?

	$hexstring = "EFAECA";
	$bytes = pack("H*", $hexstring);

This is packed "high-nybble" first. The first byte output is 0xEF, then
0xAE instead of 0xFE, followed by 0xEA.

If this isn't what you need, can you give an example of what you want to
do? Like,

print convert("ABCD")
(a series of bytes representing a bit vector issues forth)

  pack() loves me
    pack() loves me not
      pack() loves me
        pack() loves me not
          pack() loves me
            pack() loves me not
              pack() loves me
                pack() loves me knot [sic]

On Thu, 25 Jul 2002, Orr, Chuck  (NOC) wrote:

> OK,  all I need to do now is PACK, (I think) a hexedecimal into an
> alphanumeric...I've read SAMS book on the subject, but no help yet.

Andrew B. Sweger -- The great thing about multitasking is that several
                                things can go wrong at once.

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org

More information about the spug-list mailing list