hi

well my problem is , that i have a file with some ranges in it . something like :

39887-399900 23-900 8000-10000 50000-1000500 ... and so on ...
what i need is to create a file with inverse values(or to be more precise, ranges that are intact in my file). for example: (the total range is 100000000.) for values stated, the resulting ranges would be (resulting file) :

0-22 901-7999 10001-39886 1000501-100000000

one way to to this is with grep function, but ONLY for SMALL numbers. like:

my @v = grep{my $x = $_; not grep{$x == $_}(100..200)}(1..1000); my @z = grep{my $x = $_; not grep{$x == $_}(170..350)}@v;
and then retrieve first and last value in consecutive array of numbers - i now this is dumm way of doing this but nothing better is getting to me right now. so if anyone has an idea or a hint, please hint me...

thank you !

Update:

to Corion:

ok but this does not solves the problem with overlapping regions like for 39887-50000-399900-1000500

so this algorithm(trick) solves just the half of the problem !!!that is why i was thinking of greping because that way i would remove the flanking regions


In reply to greping big numbers by baxy77bax

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.