...cannot trust the files to be in sequence, but
they will be in order, the gap will be unspecific

Woah! That really throws a monkey wrench in things. So the file 9999 might not even exist, but 9998 and 0000 will? Hrmm....this calls for another solution. Let's have the program make a best guess as to where the selection of files actually begins. First, some code to generate "random elmos" (but not infinite elmos!):

my ($rand,%seen,@files); my $number=shift || 15; { $rand = substr(rand,-7,4); unless ($seen{$rand}++) { ## Files must be unique! push @files, "elmo$rand.txt"; --$number or last; } redo; }

And here's the actual code. Globbing is a better way for actual use, of course.

my @files = <elmo*.txt>; ## Convert the list to numbers and warn about any unusual elmos: @files = map { m/^elmo(\d{4})\.txt$/ and $1 or die "What is $_ doing here?!\n"; } @files; ## Now figure out where the largest gap is: my ($diff,$old,$high); for (sort @files) { $diff=$_-$old and $high=$_ if $_-$old>$diff; $old=$_; } ## Now go in order, starting at the first value after the gap: for ( map {$_->[0]} sort {$a->[1] <=> $b->[1] } map {[$_, $_ >= $high ? $_-10000 : $_]} @files) { print "Parsing elmo$_.txt\n"; }

In reply to Re: processing logic help by turnstep
in thread processing logic help by agoth

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.