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

Bad advice.

File::Find has been part of the core Perl distribution forever. If it isn't available on your host, it means their installation of Perl is incomplete. Complain to them and if they don't react, move to somewhere else. There is no excuse for not offering File::Find.

I feed in a ls -laR listing
How robust is your ls parsing pattern? And why not use find for the job of find? Something like the following does all you want, with minimal coding of your own. $ file . -type f -name '*.shtml' -print0 | xargs -0 ./myscript.pl Iterate over @ARGV using the diamond operator; it might even suffice to do something like $ file . -type f -name '*.shtml' -print0 | xargs -0 perl -i.old -pe's!/main\.php\?page=!/id=!g' See perldoc perlrun. Use the tools intended for your job to do your job, don't reinvent round wheels.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^2: Massive File Editing
by Zapawork (Scribe) on Dec 16, 2002 at 19:28 UTC
    Hi Aristotle,

    Had no idea File::Find was part of the core distribution. The reason I did not use a find function in my example was I had to parse each file in the filesystem.

    Why? We had a 2 terrabyte file system from a litigation that we needed to type, index, hash and store in a mysql database. Then when we needed to find files of certain types, patterns, sizes, dates we could query a hashed index instead of running find each time. I agree that if you are looking for a certain type of file this is not the best idea, however in my situation it had to be done. However, if you know of a better way to do this, PPLLEEASSEE let me know.

    Not the best advice, but it worked for me.

    Dave -- Saving the world one node at a time

      I see your point - and I concur that using a database was the better choice in this case (locate operates much in the same way, f.ex). Though I'd still use File::Find or at least find instead to scan the filesystem - the pertinent file information can more robustly be retrieved by (lstat|stat)ing the files yourself rather than parsing ls' output. In general, the less parsing you do, the better.

      Makeshifts last the longest.