Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Some File::Find woes. ($_ not $name)

by tye (Sage)
on Jan 12, 2004 at 21:50 UTC ( [id://320787]=note: print w/replies, xml ) Need Help??


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.

                - tye

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
    Thank you, this solved the system cache problem. I also took the other posts to heart and may try those solutions too.

    Thanks all!

    $ echo '$0 & $0 &' > foo; chmod a+x foo; foo;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://320787]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-16 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found