From owner-freebsd-questions@FreeBSD.ORG Thu Apr 29 20:09:30 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 17EB516A4CF for ; Thu, 29 Apr 2004 20:09:30 -0700 (PDT) Received: from wonkity.com (wonkity.com [65.173.111.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id A143F43D2D for ; Thu, 29 Apr 2004 20:09:29 -0700 (PDT) (envelope-from wblock@wonkity.com) Received: from wonkity.com (localhost [127.0.0.1]) by wonkity.com (8.12.11/8.12.11) with ESMTP id i3U39R52034460; Thu, 29 Apr 2004 21:09:27 -0600 (MDT) (envelope-from wblock@wonkity.com) Received: from localhost (wblock@localhost) by wonkity.com (8.12.11/8.12.11/Submit) with ESMTP id i3U39QOS034457; Thu, 29 Apr 2004 21:09:26 -0600 (MDT) (envelope-from wblock@wonkity.com) Date: Thu, 29 Apr 2004 21:09:26 -0600 (MDT) From: Warren Block To: JJB In-Reply-To: Message-ID: <20040429205041.N34394@wonkity.com> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: clamd / ClamAV version devel-20040424, clamav-milter version 0.70k cc: questions@freebsd.org Subject: Re: pad ip address with leading zeros in perl script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Apr 2004 03:09:30 -0000 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