in reply to Re: Re: Summarizing an array of IP's
in thread Summarizing an array of IP's

Make sure that you have "use Socket" included as showed in demo code. That's the module where you get inet_aton() and inet_ntoa(). (Be careful, this is not the same module as "IO::Socket".)

The code was actually tested and worked. Here is the testing result:

192.168.10.0 has 3 nodes 192.168.1.0 has 2 nodes 10.0.0.0 has 3 nodes

Update:

Read carric's reply. carric, whenever you copy and paste code, you should remove those '+' signs indicating line breaks. Those are not part of the original code.

Replies are listed 'Best First'.
Re: Re: Re: Re: Summarizing an array of IP's
by carric (Beadle) on Jan 08, 2004 at 01:30 UTC
    $ perl test syntax error at test line 15, near "+)" Execution of test aborted due to compilation errors.
    use Socket; use strict; use warnings; my %stat; my @addr = 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); $stat{inet_ntoa(substr(inet_aton($_), 0, 3) . "\0")} ++ foreach (@addr ++); print "$_ has $stat{$_} nodes\n" foreach (keys %stat);

    This is what I get. I copy and paste as is as my first test. I am using cygwin. I need to learn more about using Socket because I work a LOT with IP's and subnets. I need to sort IP's right now, so I'm working on that now. Thank you again.

    Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY USE_64_BIT_INT USE_LARGE_FILES PE +RL_IMPLICIT_CONTEXT Built under cygwin Compiled at Aug 29 2003 12:06:59 %ENV: CYGWIN="" @INC: /usr/lib/perl5/5.8.0/cygwin-multi-64int /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/cygwin-multi-64int /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl .