On Wed, 19 Sep 2007 17:06:10 -0500
"Daryl Fallin" <darylvf gmail.com> wrote:
> I haven't posted for awhile and still consider myself a
total PERL
> newbie, so I use the following perl to convert decimal
IP notation to
> Quad IP notation. Is there a better way?
>
> Also as you can see my use of $_[0] which works, but
seems odd. Now
> I can't remember why I did it that way.
>
> ###########################
> # subroutine: getip( $int )
> ###########################
> sub getip
> {
> my $ipinteger = $_[0];
> #print "TEST: $_[0]n";
> my $ipbin = ip_inttobin($ipinteger, 4);
> my $ipquad = ip_bintoip($ipbin, 4);
> my $TypeIP = new Net::IP ($ipquad) or die
(Net::IP::Error());
> #print "**IP IS: $ipquadn";
> return $ipquad;
> }
>
I'd check CPAN as I'm sure something like
NetAddr::IP::Util
might have something already written to do this.
But, the two comments I would make about the code are:
1) Don't use the indirect object syntax, it can cause
subtle
problems in the long run. So instead do:
my $TypeIP = Net::IP->new($ipquad) or die
(Net::IP::Error());
2) Why are you even creating the Net::IP object? You
don't appear to
do anything with it at all so it is pointless.
-------------------------------------------------------
Frank Wiles, Revolution Systems, LLC.
Personal : frank wiles.org http://www.wiles.org
Work : frank revsys.com http://www.revsys.com
_______________________________________________
kc mailing list
kc pm.org
http://mail.pm
.org/mailman/listinfo/kc
|