in reply to Some File::Find woes.
You are doing this very inefficiently. File::Find goes to the trouble to chdir into the directory that holds the files you are looking at and then you do operations on a long path string1 which means the operating system needs to reparse the path and pull information about all of the parent directories out of (and perhaps in to) the cache.
First, set $File::Find::dont_use_nlink= 1; (to make your script portable -- it won't be using this on Win32 since Win32 file systems just don't work that way), then use -M _ instead of your current -M $file, unlink($_) instead of unlink($file), and (much less importantly) use $_ =~ m|\.pdf$| (and you can drop the $_ =~ part if you so desire).
Note that I said -M _ and not -M $_, the former being a bit more efficient because $File::Find::dont_use_nlink= 1; assures that File::Find has already done an lstat on $_ for you so you don't need to do it again.
1 ...which might even be incorrect if $ARGV[0] didn't contain an absolute path name. I'd have to reread the File::Find docs to determine that, but what you do to fix this is the same regardless so I won't.
(updated: trivial)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Some File::Find woes. ($_ not $name)
by ibanix (Hermit) on Jan 13, 2004 at 20:14 UTC |