Date: Thu, 29 Apr 2004 21:09:26 -0600 (MDT) From: Warren Block <wblock@wonkity.com> To: JJB <Barbish3@adelphia.net> Cc: questions@freebsd.org Subject: Re: pad ip address with leading zeros in perl script Message-ID: <20040429205041.N34394@wonkity.com> In-Reply-To: <MIEPLLIBMLEEABPDBIEGAEAOFNAA.Barbish3@adelphia.net> References: <MIEPLLIBMLEEABPDBIEGAEAOFNAA.Barbish3@adelphia.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 29 Apr 2004, JJB wrote: > I have perl script written be someone else and I need to fill in the > each octal with leading zero if needed, so ip address can be sorted > on. > > This must be an very common requirement. If you're trying to sort IP addresses that way, maybe. Some modules let you get around that much easier, like the inet_aton and inet_ntoa routines in Socket. > Is there some standard perl module I can use to perform this task? Well, Socket, and also look at NetAddr::IP (/usr/ports/net-mgmt/p5-NetAddr-IP). > An sample of the perl code to accomplish this would be very helpful. Something I copied from elsewhere: my @sorted = map inet_ntoa($_), sort map inet_aton($_), @iplist; Split and join can be used to separate and rejoin the octets, but the modules are probably better. Perl questions in general should be sent to a Perl-specific mailing list or newsgroup. -Warren Block * Rapid City, South Dakota USA
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040429205041.N34394>