Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: Why are my digits disappearing? Message-ID: <109855@convex.convex.com> Date: 5 Dec 90 06:15:37 GMT References: <136559@pyramid.pyramid.com> Sender: usenet@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Distribution: na Organization: CONVEX Software Development, Richardson, TX Lines: 21 In article <136559@pyramid.pyramid.com> mfrost@pyramid.com (Mark Frost) writes: >Anyway, I've got another problem that has really been puzzling me. As part >of a larger script I am writing which deals extensively with IP addresses, >I am trying to convert decimal IP addresses to hex format. So 129.214.009.096 >would give me "81D60960". I didn't look too closely at your code, because it looks like you're working way, way too hard. I would just do this: sub in2hex { sprintf('%02X' x 4, split(/\./, $_[0])); } Of course, this isn't really like inet_addr(3N), as that will accept addresses in the form a.b and a.b.c as well as a.b.c.d, which is the only form this rendition works for. Accepting the other forms I leave as an exercise to the reader. :-) --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "With a kernel dive, all things are possible, but it sure makes it hard to look at yourself in the mirror the next morning." -me Brought to you by Super Global Mega Corp .com