Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I think your original suggestion, of using Net::CIDR::cidr2range and merging the ranges end-to-end, was better. Your new program seems to be slower than the one I wrote following your Net::CIDR suggestion. Here's my program for comparison:
#!/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(); }
I ran your program on and waited three minutes. Then I started my program. My program finished first.

Of course, I might have made a mistake in the benchmarking somewhere.

Mark Dominus
Perl Paraphernalia

In reply to Re: Merge CIDRs by Dominus
in thread Merge CIDRs by merlyn

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (7)
    As of 2021-01-22 11:47 GMT
    Find Nodes?
      Voting Booth?