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

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!world!dsb
  3. From: dsb@world.std.com (David Boyce)
  4. Subject: Re: easy question?: substrings
  5. Message-ID: <BtM69K.54J@world.std.com>
  6. Organization: The World Public Access UNIX, Brookline, MA
  7. References: <1992Aug26.213516.22813@cbnewse.cb.att.com> <1992Aug26.222821.28341@news.eng.convex.com>
  8. Distribution: usa
  9. Date: Wed, 26 Aug 1992 23:22:31 GMT
  10. Lines: 24
  11.  
  12. In article <1992Aug26.222821.28341@news.eng.convex.com> tchrist@convex.COM (Tom Christiansen) writes:
  13. >From the keyboard of budnick@cbnewse.cb.att.com (Mary Jo Budnick):
  14. >:Hi!  I just started to use Perl and can't find the info in the
  15. >:Wall/Schwartz book very easily to solve my problem.  Help me out?
  16. >:
  17. >:All I want to do is to change a string in the format of either
  18. >:    0xffffff00 or ffffff00 into the format
  19. >:    of 255.255.255.0 
  20. >
  21. >Try:
  22. >
  23. >    $n = "ffffff00";
  24. >    print join(".", unpack(C4, pack(L, hex($n)))), "\n";
  25. >
  26. >Add quotes around the format strings for old versions of perl.
  27.  
  28.     Or what I find less obfuscated:
  29.  
  30. $n = "0xffffff00";
  31. ($junk, $f1, $f2, $f3, $f4) = $n=~/(0x|)(..)(..)(..)(..)/;
  32. printf "%d.%d.%d.%d\n", hex($f1), hex($f2), hex($f3), hex($f4);
  33.  
  34. -- 
  35. David Boyce    dsb@world.std.com    617-576-1540
  36.