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??
Set::IntSpan can provide relevent routines when working with (connected) ranges of numbers. Although it can work with array references it can be initialized with just a string (and so you save a lot of memory).

#!/usr/bin/perl use strict; use warnings; use Set::IntSpan; my $range = Set::IntSpan->new( '50000-65535' ); my $used = Set::IntSpan->new( '50000-51545,51549,51555-51999' ); my $unused = $range->diff( $used ); my @newports; while (my $port = $unused->next) { print $port, "\n"; push @newports, $port; last if @newports == 10; } print "Unused before newports: ", $unused->run_list, "\n"; for (@newports) { $unused->remove($_); $used->insert($_); } print "Unused after newports: ", $unused->run_list, "\n"; print "Used after newports: ", $used->run_list, "\n"; __END__ C:\Old_Data\perlp>perl 51546 51547 51548 51550 51551 51552 51553 51554 52000 52001 Unused before newports: 51546-51548,51550-51554,52000-65535 Unused after newports: 52002-65535 Used after newports: 50000-52001
Update: Well, as it happens, I shouldn't make statements about that which I don't know (well). The documentation says:

Sets are stored internally in a run-length coded form. This provides for both compact storage and efficient computation. In particular, set operations can be performed directly on the encoded representation...

In reply to Re: fastest way to compare two arrays by Cristoforo
in thread fastest way to compare two arrays by krusty

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 all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (3)
    As of 2018-06-24 06:09 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (126 votes). Check out past polls.