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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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"


In reply to Re: File::Find problem by arturo
in thread File::Find problem by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found