Earl Hood wrote:
...
I've hacked together:
sub new_get_last_msg_num {
opendir(DIR, $'OUTDIR) || &error("ERROR: Unable to open $'OUTDIR");
local ($max) = -1;
grep { /msg0*(\d+).html/; $max=$1 if $1 > $max; } readdir(DIR);
close(DIR);
$max;
}
The above is not legal perl 4. See if the following is comparable
in speed performance:
sub get_last_msg_num {
opendir(DIR, $'OUTDIR) || &error("ERROR: Unable to open $'OUTDIR");
local($max) = -1;
foreach (readdir(DIR)) {
if (/msg0*(\d+).htm/) {
even better: /^msg0*(\d+).htm/
$max = $1 if $1 > $max;
}
}
close(DIR);
$max;
}
It's even faster in perl5. Seem that building the array returned by
readdir takes longer than doing the loop in perl. I made your regexp
even a bit faster by anchoring it to the begin of the string:
ehood sub: (max=1531) timethis 10: 5 secs ( 2.30 usr 0.13 sys = 2.43 cpu)
ehood ^ sub: (max=1531) timethis 10: 5 secs ( 2.28 usr 0.18 sys = 2.47 cpu)
ach sub: (max=1531) timethis 10: 5 secs ( 2.88 usr 0.27 sys = 3.15 cpu)
ach ^ sub: (max=1531) timethis 10: 5 secs ( 2.82 usr 0.23 sys = 3.05 cpu)
Achim
--ewh