#!/usr/bin/perl -i.bak -w # inplace.pl A short program to edit all the files in a dir inplace use strict; my $dir = 'c:/test1'; my @files; opendir(DIR, $dir) or die "Can't open dir $dir, Perl says $!\n"; while (my $file = readdir DIR) { # only push in the files not the dirs - use full path! push @files, "$dir/$file" unless -d "$dir/$file"; } closedir DIR; # now do an inplace edit. use a bare block and local to limit # the scope of our changes to the global @ARGV array to just here { local @ARGV = @files; # set up a temporary @ARGV for in-place ed +it while (<>) { s/this/that/; # modify the file print; # print the modifications } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inplace Editing
by rob_au (Abbot) on Aug 21, 2001 at 09:43 UTC | |
by clemburg (Curate) on Aug 21, 2001 at 21:41 UTC | |
|
Re: Inplace Editing
by $code or die (Deacon) on Aug 21, 2001 at 17:56 UTC | |
|
Re: Inplace Editing
by WAP_happens (Initiate) on Aug 21, 2001 at 20:27 UTC | |
by Hofmator (Curate) on Aug 21, 2001 at 21:00 UTC |