Ok, that helps. If your files are indeed line-based (i.e., your patterns do not span multiple lines), then I suggest processing them line-by-line:
use File::Slurp; my @myHashArray = ( { toFind => qr/(?i)foo/, toReplace => 'bar' } ); my $counter = 0; my $name = 'data_file'; # $File::Find::name for my $line (read_file('data_file', chomp => 1)) { $counter++; my $orig_line = $line; $line =~ s/$_->{toFind}/$_->{toReplace}/g for @myHashArray; next if $line eq $orig_line; print "LOG: $counter $name\n"; print "LOG: \t Original line: $orig_line\n"; print "LOG: \t Replaced line: $line\n"; }
Here I've replaced LOGFILE with a LOG: prefix for ease of testing, and eliminated the reliance on File::Find for the same reason.
With the following data_file:
Foolius Caesar Footholomew Cubbins No changes here Just another barrage of text
I get the following output:
LOG: 1 data_file LOG: Original line: Foolius Caesar LOG: Replaced line: barlius Caesar LOG: 2 data_file LOG: Original line: Footholomew Cubbins LOG: Replaced line: bartholomew Cubbins
Does that help?
In reply to Re^3: array of hashes help
by rjt
in thread array of hashes help
by rv799cv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |