my $get_ipv4 = sub {
my ( $ip , $i , $n ) = ( '' , 0 , 0 ) ;
map { $ip =
( length ( $_ ) and
( $n = int $_ ) and
$n >= 0 and
$n <= 255 and
++$i < 4 or
( $i == 4 and $n > 0 )
)
? ( length ( $ip ) ? $ip . "." . $n : $n )
: '' ;
} split ( /[^\d]+/ , shift ) ;
return ( $ip ) if ( my @octet = split /\./ , $ip ) == 4 ;
} ;example--
Works with stuff this bad--won't allow n.n.n.0 though. almost war_ipv4()
print "\n" . $get_ipv4->(' x #comment127.0.0.1 #comment ') ;
print "\n" . $get_ipv4->(' x #comment027.0.9.1 #comment ') ;
print "\n" . $get_ipv4->(' x #comment027.0.09.1 #comment ') ;
print "\n" . $get_ipv4->(' x #comment127.0.999.1 #comment ') ;
print "\n" . $get_ipv4->(' x #comment127.0.0.0 #comment ') ;
print "\n" . $get_ipv4->(' x #comment255.255.255.255 #comment ') ;
print "\n" . $get_ipv4->('0255.0255.0255.0255') ;
print "\n" . $get_ipv4->(' x #comment0.0.0.0 #comment ') ;
print "\n" . $get_ipv4->('0.0.0.0') ;-Bob Dodds
