agoth has asked for the wisdom of the Perl Monks concerning the following question:
The code I have come up with is below but is rather kludgy. Can anyone suggest improvements to the logic please??
cheers
my %temp = (); my %files = (); my ($zeroes, $nines) = (0,0); my $lastkey = 0; # lastfile contains number open (QS, $lastfile) or die "cant open $lastfile $!"; while (<QS>) { $lastkey = $_; } close QS; # <> contains the list of files from a .sh while (<>) { chop; next if $_ !~ /\.txt$/; my $file = $indir.$_; $_ =~ s/elmo(\d*)\.txt$/$1/; $temp{$_} = [ $file, $_ ]; $nines = 1 if $_ =~ /^999/; $zeroes = 1 if $_ =~ /^000/; } for (keys %temp) { my $k = $_; if (($nines && $zeroes) || ($zeroes && $lastkey =~ /^99/)) { $k += 10000 if ($k =~ /^000/); $lastkey += 10000 if ($lastkey =~ /^00/ && $lastkey < 9999); } $files{$k} = [ @{ $temp{$_} }]; } for (sort {$a <=> $b} keys %files) { my $file = $files{$_}->[0]; my $numkey = $_; if ($numkey > $lastkey) { if (-e $file){ # &io_process_file($lda, $file, 'incstock', \&load_incstock, + 1); $lastkey = $numkey; $lastkey += 10000 if (($nines && $zeroes) && $lastkey < 900 +0); } } } open (QS, ">$lastfile") or die "cant open $lastfile $!"; print QS $files{$lastkey}->[1]; close QS;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: processing logic help
by chromatic (Archbishop) on Sep 13, 2000 at 18:54 UTC | |
|
Re: processing logic help
by merlyn (Sage) on Sep 13, 2000 at 19:02 UTC | |
|
RE (tilly) 1: processing logic help
by tilly (Archbishop) on Sep 13, 2000 at 18:59 UTC | |
|
Re: processing logic help
by araqnid (Beadle) on Sep 13, 2000 at 17:39 UTC | |
|
processing logic help (2)
by agoth (Chaplain) on Sep 13, 2000 at 19:50 UTC | |
|
Re: processing logic help
by turnstep (Parson) on Sep 15, 2000 at 00:44 UTC |