in reply to Summarizing an array of IP's

If what you mean by node is unique values:
use strict; use warnings; my %ips; my @array = qw ( 10.0.0.1 10.0.0.2 10.0.0.3 192.168.1.5 192.168.1.6 192.168.10.3 192.168.10.4 192.168.10.5 10.0.0.1); foreach (@array) { $ips{$1}{$2} = undef if /([\d.]+)\.(\d+)$/; } foreach ( keys %ips ) { my $keys = keys %{$ips{$_}}; print "$_: $keys nodes\n" }

If by nodes you meant values appearing regardless of possible duplication:

use strict; use warnings; my %ips; my @array = qw ( 10.0.0.1 10.0.0.2 10.0.0.3 192.168.1.5 192.168.1.6 192.168.10.3 192.168.10.4 192.168.10.5 10.0.0.1); foreach (@array) { $ips{$1}++ if /([\d.]+)\.(\d+)$/; } foreach ( keys %ips ) { print "$_: $ips{$_} nodes\n" }

(Note the different value of 10.0.0 caused by the extra 10.0.0.1 in the array)

-enlil

Replies are listed 'Best First'.
Re: Re: Summarizing an array of IP's
by carric (Beadle) on Jan 06, 2004 at 22:20 UTC

    This looks like the closest to what I am after. I apologize for not being clearer.. I want to produce a report of how many network nodes there are per class C subnet (this is not a class C, in fact I scanned a class B, but the data is more digestable if I just show the "class C chunks" that contained live hosts).

    Thanks a lot for the help!!