in reply to Merge CIDRs
I ran your program on nm5.in and waited three minutes. Then I started my program. My program finished first.#!/usr/bin/perl use Net::CIDR 'cidr2range', 'range2cidr'; my @ranges; my ($cur_start, $cur_end, $cs, $ce); while (<>) { chomp; my @r = cidr2range($_); my ($r_start, $r_end) = split /-/, $r[0]; my ($rs, $re) = map {inet_to_n($_)} $r_start, $r_end; if (! defined $cur_start) { ($cur_start, $cur_end) = ($r_start, $r_end); ($cs, $ce) = ($rs, $re); } else { if ($rs == $ce + 1) { $cur_end = $r_end; $ce = $re; } else { print join "\n", range2cidr("$cur_start-$cur_end"), ""; ($cur_start, $cur_end) = ($r_start, $r_end); ($cs, $ce) = ($rs, $re); } } } continue { print STDERR "$. records processed\n" if $. % 1000 == 0; } print join "\n", range2cidr("$cur_start-$cur_end"), "" if defined $cur_start; sub inet_to_n { unpack "N", pack "C4", split /\./, shift(); }
Of course, I might have made a mistake in the benchmarking somewhere.
--
Mark Dominus
Perl Paraphernalia
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Merge CIDRs
by merlyn (Sage) on Oct 15, 2001 at 05:44 UTC | |
by Dominus (Parson) on Oct 15, 2001 at 09:50 UTC |