Next | Program Repair Shop | 187 |
With the indentation fixed, it appears that this code isn't so bad
(a lot better than some of the other code in this class)
The major error is that $dir is opened and read repeatedly
This doesn't depend in any way on $key
Code that doesn't depend on the loop variable at all is called invariant
It can often be hoisted out of the loop:
my $dir = $build_photo_path; opendir(DIR, $dir) || &err("can't open : $!"); @all_files = readdir(DIR); closedir(DIR);
foreach $key (keys %delete_list) { my (@files) = (); &header; @files = grep { /$key\.*/i } @all_files; if ($#files > -1) { foreach (@files) { unlink("$dir/$_") || &err("can't delete $_ : $!"); } } }
Next | Copyright © 2002 M. J. Dominus |