home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5518 < prev    next >
Encoding:
Text File  |  1992-08-26  |  1.2 KB  |  39 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!gatech!destroyer!ubc-cs!dhami
  3. From: dhami@cs.ubc.ca (Mandeep S Dhami)
  4. Subject: > easy question?: substrings
  5. Message-ID: <1992Aug26.231400.4544@cs.ubc.ca>
  6. Keywords: unpack,hex
  7. Sender: usenet@cs.ubc.ca (Usenet News)
  8. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  9. Date: Wed, 26 Aug 92 23:14:00 GMT
  10. Lines: 27
  11.  
  12. From budnick@ihspa.att.com:
  13. > All I want to do is to change a string in the format of either
  14. >     0xffffff00 or ffffff00 into the format
  15. >     of 255.255.255.0 
  16. > The part I'm having trouble w/ is splitting the ffffff00 string
  17. > into an array of: ff ff ff 00.  After I do that I plan to
  18. > change these array elements into decimal from hex and join
  19. > with a ".".  But,  I can't find a good way to successively cut
  20. > 2 chars from the ffffff00 string.
  21. >  
  22.  
  23. Try -
  24. $x="ffefab30";  # Or whatever way.
  25. $y=join(".",grep($_=hex,unpack("a2a2a2a2",$x)));
  26.  
  27. Or to print -
  28. print join(".",grep($_=hex,unpack("a2a2a2a2","ffefab30"))),"\n";
  29.  
  30. Mandeep.
  31.  
  32. --
  33. __________________________________________________________________
  34. "I'm very brave generally," he went on in a low voice:
  35. "only to-day I happen to have a headache."
  36.                                       -- Lewis Carroll
  37.