Do the files exist in the given paths on the machine running the code? If so, you can validate each "edit".
I'd alter the regex creation slightly:
use strict; use warnings; my $paths = <<PATHS; /unix/path/to/folder/is/here /unix/path/to/folder/is/somewhere /unix/path/to/folder/is/herewith PATHS open my $file_paths, '<', \$paths; my $references = join '|', map {chomp; qr/\Q$_\E/} sort {length($b) <=> length($a)} <$file_paths>; print join "\n", split ('\|', $references), ''; for my $test ( "/unix/path/to/folder/is/herewitha_file.txt", "/unix/path/to/folder/is/herea_file.txt" ) { $test =~ /($references)/; print "$1\n"; }
Prints:
(?^:\/unix\/path\/to\/folder\/is\/somewhere) (?^:\/unix\/path\/to\/folder\/is\/herewith) (?^:\/unix\/path\/to\/folder\/is\/here) /unix/path/to/folder/is/herewith /unix/path/to/folder/is/here
which ensures longer matches are made first. In the example code commenting out the sort results in:
(?^:\/unix\/path\/to\/folder\/is\/here) (?^:\/unix\/path\/to\/folder\/is\/somewhere) (?^:\/unix\/path\/to\/folder\/is\/herewith) /unix/path/to/folder/is/here /unix/path/to/folder/is/here
In reply to Re: In place replacement from reference list
by GrandFather
in thread In place replacement from reference list
by Misstre
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |