Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: File::Find problem

by arturo (Vicar)
on Mar 17, 2003 at 17:41 UTC ( [id://243704]=note: print w/replies, xml ) Need Help??


in reply to File::Find problem

I have a suggestion about a redesign that might help (although I'll admit I haven't figured out why your code isn't working -- one guess is that you're reading the perldocs for the wrong version of File::Find, but I don't know off the top of my head at which version the pre- and post- process options were added, but defeasible memories suggest it is VERY recent; check perldoc File::Find on your own system to see if your version supports these options).

My suggestion is this: do away with the flag variable, and just have your "wanted" routine process the directory itself.

sub process { return unless -d; opendir DIR, $_ or die "Can't open $File::Find::name: $!\n"; my @old = grep /\.old$/i, readdir DIR; closedir DIR; return unless @old; # now write what you have to }

This is a little bit inefficient (it ends up reading the directory twice), but I think it gains a bit in clarity. If my guess above is right, it will work whereas your current algorithm won't unless you upgrade perl (or at least File::Find) on your system.

There are a few things you're doing that don't comport with what you say you want to do. Do you want to append lines to the CPB files or do you want to write new ones? Also, that else in the postprocess sub is unnecessary.

update shoulda checked the File::Find docs .. .the pre and postprocess facility has been there for a very long time, so my guess is wrong. Musta blocked that part of the docs out. Also, go ahead and disregard the comment about "appending", I hadn't read that part of your code very closely.

If not P, what? Q maybe?
"Sidney Morgenbesser"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (1)
As of 2024-04-24 16:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found