in reply to Re: Massive File Editing
in thread Massive File Editing

For each file or directory you find with File::Find, you're finding all of the files in its containing directory with File::Glob. You don't really need File::Glob.

Replies are listed 'Best First'.
Re: Re: Re: Massive File Editing
by pg (Canon) on Dec 15, 2002 at 15:54 UTC
    I know this. The purpose of using File::Glob here is to reduce coding effort, so you don't need to match file name patterns on your own. When File::Glob can do this for you, what is the point to reinvent it?

    I would agree File::Glob is too much a waste, if File::Find is improved to support patterns, and only return those entities, whose name match a certain pattern (ideally a regexp). But why the Perl community didn't do it? Reason is simple, because of the existance of File::Glob, there is no point to repeat/reinvent the same functionality in another class.

    If you look at this from an OO view, it does make a lot of sense. Although File::Find and File::Glob might take care of different but tightly related tasks in some programs, they still should be abstracted as two different classes.

      I'm not suggesting reinventing File::Glob. I'm suggesting that you only want to edit each file once. That's not what your code does.

      For every file or directory your code finds, it processes every .shtml file in the current directory.

      There are two ways to fix it. One, don't use File::Glob. Two, only use File::Glob if the current file from File::Find is a directory.

      if File::Find is improved to support patterns, ... But why the Perl community didn't do it? Reason is simple, because of the existance of File::Glob, there is no point to repeat/reinvent the same functionality in another class

      Nope. File::Find doesnt have any filtering mechansim explicitly built into it for a very good reason that has nothing to do with File::glob. Basically the callback mechanism used by File::Find is about a million times more powerful than any filtering technique they could have provided. If you want to do pattern matching on the names then just do it in the wanted function:

      #perl -l use File::Find; find sub{print $_ if -f and /\.txt$/i},@INC;
      will print out all text files in a directory reachable from the paths in @INC for example.

      And if this really is not sufficient (id be suprised) then take a look at File::Find::Rules

      HTH

      --- demerphq
      my friends call me, usually because I'm late....