home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / perl / 8001 < prev    next >
Encoding:
Text File  |  1993-01-27  |  1.5 KB  |  42 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!paladin.american.edu!howland.reston.ans.net!usc!cs.utexas.edu!convex!convex!tchrist
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: How to convert string to hex?
  5. Originator: tchrist@pixel.convex.com
  6. Sender: usenet@news.eng.convex.com (news access account)
  7. Message-ID: <1993Jan26.172831.18300@news.eng.convex.com>
  8. Date: Tue, 26 Jan 1993 17:28:31 GMT
  9. Reply-To: tchrist@convex.COM (Tom Christiansen)
  10. References: <C1FnMG.AMB@ibeam.intel.com> <C1Fs2F.BB3@ibeam.intel.com>
  11. Nntp-Posting-Host: pixel.convex.com
  12. Organization: Convex Computer Corporation, Colorado Springs, CO
  13. X-Disclaimer: This message was written by a user at CONVEX Computer
  14.               Corp. The opinions expressed are those of the user and
  15.               not necessarily those of CONVEX.
  16. Lines: 24
  17.  
  18. From the keyboard of gweil@ibeam.intel.com (Garry Weil):
  19. :>How do I convert "Test" to 0x54 0x65 0x73 0x74 ?
  20. :Is there something better?
  21. :BTW, I want to separate hex values with ",".
  22.  
  23. Legibility:
  24.  
  25.     while (<>) {
  26.     chop;
  27.     @a = unpack('C*', $_));
  28.     for (@a) { $_ = sprintf("0x%x", $_); } 
  29.     print join(", ", @a), "\n";
  30.     } 
  31.  
  32. Job security:
  33.  
  34.     perl -lpe '$_=join(", ",grep($_=sprintf("0x%02x",$_),unpack("C*", $_)))'
  35.  
  36. --tom
  37. -- 
  38.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  39.     "...this does not mean that some of us should not want, in a rather
  40.     dispassionate sort of way, to put a bullet through csh's head."
  41.         Larry Wall in <1992Aug6.221512.5963@netlabs.com>
  42.