See Set::IntSpan

From the doc : << 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. >>

#!/usr/bin/perl -w use strict; use Data::Dumper; use Set::IntSpan; my $good_run_list = '1-5'; my $bad_run_list = '1,3'; my ( $good_set, $bad_set, $x_set ); if ( valid Set::IntSpan $good_run_list and valid Set::IntSpan $bad_run +_list ) { $good_set = new Set::IntSpan $good_run_list; $bad_set = new Set::IntSpan $bad_run_list; } else { print "Please verify your run lists\n" } $x_set = $good_set ^ $bad_set; # Or $x_set = $good_set->X($bad_set); finite $x_set and my @elements = elements $x_set; print Dumper \@elements; __END__ Output: $VAR1 = [ 2, 4, 5 ];

hth,
PooLpi

'Ebry haffa hoe hab im tik a bush'. Jamaican proverb

In reply to Re: Subtracting Lists by poolpi
in thread Subtracting Lists by JimSki

Title:
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, details, 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, summary, 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.