@ARGV = <$responseDir/*>; while (<>) { $newFile = $ARGV, last if /^"$commonField"$/; }
Is going through each file in $responseDir opening it and reading each line. when you get a line which matches common field you will edit that file then go on to the next element of @arrFileList. Perhaps you wanted something more like
# replace from @ARGV = <$responseDir/*>; foreach $file (<$responseDir/*>) { open FH, "$responseDir/$file" or die "$!\n"; my ($edit, @temp); while (<FH>) { push @temp, $_; $edit++ if /^"$commonField"$/; } close FH; next unless $edit; open NEW, ">$responseDone/$file" or die "$!\n"; foreach (@temp) { s/$replaceField/$origField/g; print NEW; } close NEW; print "Done s/$replaceField/$origField/g $file\n"; unlink "$responseDir/$file"; print "removed original\n"; system ("mv $sourceDir/$arrFileList $processed"); print "moved $sourceDir/$arrFileList to $processed\n"; }
Cheers,
R.
In reply to Re: Help on foreach loop
by Random_Walk
in thread Help on foreach loop
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |