Rmck wrote: > > From: "John W. Krahn" <[EMAIL PROTECTED]> > > > > I would do it something like this: > > > > #!/usr/bin/perl > > use warnings; > > use strict; > > use Socket; > > > > my %IPs; > > while ( <> ) { > > $IPs{ inet_aton( $1 ) }++ if /\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b/; > > } > > > > for ( sort keys %IPs ) { > > print inet_ntoa( $_ ), "\n"; > > } > > > > print "\nTotal IP'S = ", scalar keys %IPs, "\n"; > > > > __END__ > > But, I want to be able to print the numbers that are typos, > also. like this "111.111.13473" > That script just drops them. > Is there a way I could print those at the end of the script > after the count of real ip's? > > Like: > Goal Out: > 111.111.135.11 > 111.222.81.97 > > Total IP'S = 2 > > Not Ip=111.111.13473
I take it that you only want to accept dotted quad formats because 111.111.13473 IS a valid IP address (as is 127.1 and 1234567890, etc.) #!/usr/bin/perl use warnings; use strict; use Socket; my ( %IPs, %invalid ); while ( <> ) { for ( /[\d.]+/ ) { my $valid; if ( defined( $valid = inet_aton $_ ) and $_ eq inet_ntoa $valid ) { $IPs{ $valid }++; } else { $invalid{ $_ }++; } } } for ( sort keys %IPs ) { print inet_ntoa( $_ ), "\n"; } print "\nTotal IP'S = ", scalar keys %IPs, "\n\n"; print "$_\n" for keys %invalid; __END__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>