Chetak Sasalu wrote:
> 
> Hi,

Hello,

> I have to search and replace 'foo' to 'bar' in all the files in a
> directory(has subdirectories).
> The files are about 40k in size.
> 
> On the command line I would do it as,
> find ./mydir/ -type f -print | xargs perl -pi -e  's/foo/bar/'
> 
> No backup of the original files required.I am brave.
> 
> What is the most efficient way to implement this inside a perl program ?
> There are about 30 files to be processed.
> I went through  perldoc perlrun and saw the code.
> 
> I thought it as a criminal waste of time to try and modify that code for
> my purpose, when I can ask you folks :-)

use File::Find;
local ( $^I, @ARGV ) = '';
find( { no_chdir => 1, wanted => sub { -f and push @ARGV, $_ } }, './mydir' );
s/foo/bar/g, print while <>;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to