in reply to How to Modify Each file??
Perl provides a rather nice way of modifying a list of files. The technique is mainly intended for processing a bunch of files provided on the command line, but can be manipulated slightly to allow a list generated at run time to be used instead. Consider:
use strict; use warnings; opendir my $scan, '.'; @ARGV = grep {/\.c$/} readdir $scan; closedir $scan; $^I = 'org/*'; while (<>) { print "//$_"; }
which builds a list of .c files then edits all the files in the list by adding a C++ style comment to the start of the line. It also copies the original version of each file to the subdirectory 'org'.
Except that the original is copied elsewhere and the updated file is left in the original location, this seems to be pretty close to what you are after.
See the discussion of the -i flag in perlrun.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to Modify Each file??
by shmem (Chancellor) on Oct 20, 2007 at 22:55 UTC |