in reply to Search and Replace.
In part 1, the only specifically slow substitution will be the one anchored to end of string, s/[ ]*$//g. Since the following substitutions all shorten the string you'd get a small benefit from doing this last, so combining with the other responses I'd suggest:
For the second part, you can save small amounts: substitute trailing space on the last field after splitting, instead of on the whole line; precalculate the values for $PROC_FIELDS[$i] - 1; avoid the $i loop index; avoid the block in the loop using the modifier form:while (<IN_FILE>) { s/^\ +//; s/:000[AP]M|99991231|Jan 1 1900 12:00:00//g; s/\ *-\t-\ */-/g; s/\ +$//; }
my @PROC_INDEXES = map $_ - 1, @PROC_FIELDS; while (<IN_FILE>) { s/^\ +//; s/:000[AP]M|99991231|Jan 1 1900 12:00:00//g; s/\ *-\t-\ */-/g; my @INPUT_FIELDS = split /-/, $_; $INPUT_FIELDS[$#INPUT_FIELDS] =~ s/\ +$//; /SUN/ && ($_ = '') for @INPUT_FIELDS[@PROC_INDEXES]; print OUT_FILE join '-', @INPUT_FIELDS; } close IN_FILE; close OUT_FILE;
In any case, though, all of these savings are quite minor: I suspect the majority of the time is being taken up with unavoidable I/O.
Hugo
|
|---|