home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!gatech!destroyer!ubc-cs!dhami
- From: dhami@cs.ubc.ca (Mandeep S Dhami)
- Subject: > easy question?: substrings
- Message-ID: <1992Aug26.231400.4544@cs.ubc.ca>
- Keywords: unpack,hex
- Sender: usenet@cs.ubc.ca (Usenet News)
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Date: Wed, 26 Aug 92 23:14:00 GMT
- Lines: 27
-
- From budnick@ihspa.att.com:
- >
- > 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
- >
- > The part I'm having trouble w/ is splitting the ffffff00 string
- > into an array of: ff ff ff 00. After I do that I plan to
- > change these array elements into decimal from hex and join
- > with a ".". But, I can't find a good way to successively cut
- > 2 chars from the ffffff00 string.
- >
-
- Try -
- $x="ffefab30"; # Or whatever way.
- $y=join(".",grep($_=hex,unpack("a2a2a2a2",$x)));
-
- Or to print -
- print join(".",grep($_=hex,unpack("a2a2a2a2","ffefab30"))),"\n";
-
- Mandeep.
-
- --
- __________________________________________________________________
- "I'm very brave generally," he went on in a low voice:
- "only to-day I happen to have a headache."
- -- Lewis Carroll
-