in reply to file::find

Because this one has bitten me so many times, I will warn you in big red letters ( oh the temptation for a little creative html :) that Find::File, in direct contradiction of the Principle Of Least Astonishment (POLA) and in an otherwise stupid fashion, does a chdir on you. You will not end in the same directory you started.

Either store your starting directory and go back after the File::Find is done, or write your own as I have done.

Mik
Mik Firestone ( perlus bigotus maximus )

Replies are listed 'Best First'.
RE: RE: file::find
by takshaka (Friar) on May 01, 2000 at 23:34 UTC
    Alternately, use a hashref as the first argument to find() and set the no_chdir option. find {wanted => \&wanted, no_chdir => 1}, '/dir'; Then, no chdir is done; and $_ will be the same as $File::Find::name.
      I know this is an old post, but the only documentation I found on this was to go into the module and read. There are a few flags in there that aren't mentioned in the documentation

      I don't know if your code works, b/c of the missing parens, but I use:

      find ({wanted => \&wanted, no_chdir=>1}, $dir1);

      -OzzyOsbourne

      Where is that documented? I have looked for that flag for ages. What version? A quick grep of my perl5.005_03 sources do not turn up this flag. Ah. I see. That would be new to perl 5.6.0. Cool! I can stop implementing my own Find. Thanks!

      Mik
      Mik Firestone ( perlus bigotus maximus )

        Whoops. Forgot that was new for 5.6. I knew there was a reason I hadn't used that flag on a production server.