in reply to processing logic help
...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"; }
|
|---|