in reply to removing a needle from a haystack
Depending on the data, a for loop that bails out at the first match is usually faster. Since in this case we want to avoid the readdir calls though, a while is best:
opendir(DIR, $path) or die("No opendir on $path\n"); while (defined($_ = readdir DIR)) { if (/^${id}\_.*$/o) { $filename = "$path/$_"; last; } } closedir(DIR); if ($filename) { unlink($filename) or die("No unlink on $filename\n"); }
|
---|