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