How is this:

use strict; use warnings; my @a = qw(0 6:4 12:8 19:31); my %b; for (@a){ if (!/:/){ $b{$_}=1; } else { my($a,$b) = split(/:/, $_); ($a,$b)=($b,$a) if $a>$b; $b{$_}=1 for($a..$b); } } print join(" ", grep {!exists $b{$_}} (0..31)), "\n";

Update:

In avoidance of tax filing, I carried on... You asked for 13:18, and later 18:13. This converts 0 6:4 12:8 19:31 to 1:3 7 13:18.

use strict; use warnings; my @a = qw(0 6:4 12:8 19:31); my $s = ''; vec($s,0,32) = 0; for (@a){ if (/(\d+):(\d+)/){ vec($s,$_,1) = 1 for(($1<$2) ? $1..$2 : $2..$1); } else { vec($s,$_,1) = 1; } } my @bits = split(//,unpack("b*",$s)); my $series = 0; for(0..31){ if ($bits[$_] eq 0) { if (!$series) { print; $series = $_; } } else { if ($series) { print ( ($series+1 < $_) ? ':'.($_-1).' ' : ' '); } $series = 0; } }

In reply to Re: screen out an untained array from a special array by hbm
in thread screen out an untained array from a special array by Hanken

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.