List Info

Thread: Since everyone is on a roll today .. is this the most efficient ...




Since everyone is on a roll today .. is this the most efficient ...
user name
2007-09-19 17:06:10
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;
}
Re: Since everyone is on a roll today .. is this the most efficient ...
country flaguser name
United States
2007-09-19 17:14:15
On Wed, 19 Sep 2007 17:06:10 -0500
"Daryl Fallin" <darylvfgmail.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 : frankwiles.org  http://www.wiles.org
     Work     : frankrevsys.com http://www.revsys.com 

_______________________________________________
kc mailing list
kcpm.org
http://mail.pm
.org/mailman/listinfo/kc

Re: Since everyone is on a roll today .. is this the most efficient ...
user name
2007-09-19 17:29:17
On 9/19/07, Daryl Fallin <darylvfgmail.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;
> }

You could do:
   my $ipinteger = shift;

or maybe:
   # this is one is weird since you don't have a list of
arguments
   my ($ipinteger) = _;

As FrankW said, I also am not sure why you are even creating
the object.
_______________________________________________
kc mailing list
kcpm.org
http://mail.pm
.org/mailman/listinfo/kc

Re: Since everyone is on a roll today .. is this the most efficient ...
user name
2007-09-20 11:06:24
On 9/19/07, djgoku <djgokugmail.com> wrote:
> You could do:
>    my $ipinteger = shift;

or wait until Macrame is available and do

    macro ipinteger {_[0]}

but at this time it's still a vaporware victim of the
ongoing tuit
shortage crisis
_______________________________________________
kc mailing list
kcpm.org
http://mail.pm
.org/mailman/listinfo/kc

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )