SPUG: Math Genius

Orr, Chuck (NOC) chuck.orr at attws.com
Thu Jul 25 20:56:26 CDT 2002

Thanks for all the replies,

I actually did not need pack or tr.  The previous script writer had made up
his own system where by 0-9 maintains its value and 10-35 become the letters
A-Z respectively.

A kind gentleman named David Dyck helped me out with the following

substr("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", $_, 1)

which worked like a charm.

Thanks again to all,

-----Original Message-----
From: Andrew Sweger [mailto:andrew at sweger.net]
Sent: Thursday, July 25, 2002 6:52 PM
To: Orr, Chuck (NOC)
Cc: Seattle Perl Users Group
Subject: RE: SPUG: Math Genius

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