Howdy:
I'm trying to find the best solution for breaking
out of a loop when editing a list of files.
I have a script that:
* gets a list of files
* opens the files with a 'foreach $f(@list)'
* does a 'while <> { ... } close (FILE)'
The script works, but if I run it, it loops
continually and edits (then re-edits) the files.
I think I could use a lock file to do until I
get a particular file, but I'm not sure how
to go about it - at the same time, it may not be
the more productive way to go.
[--snip script--]
my @list = grep {/\.txt/ } readdir(DIR) or die "Can not read the dir\n";
# create a loop to search for instances of
# control characters and change it to something else
foreach $file(@list) {
open (FILE, $file) or die "can not open this file: $!";
local $^I=".bak"; # to keep a backup of the files
# set to "" if i don't want backups
local @ARGV = @list; # the files to work on
while (<>) {
s!$pattern!$new_ptrn!g ;
print;
} # end while loop
close (FILE);
} #end of for loop
close (DIR);
__END__
[/--snip script--]
Any suggestions? Thanks!
-X