jynx has asked for the wisdom of the Perl Monks concerning the following question:
It is often quite useful to change text in multiple files at the same time. Although there is a one-liner for changing all files in current directory, i wanted to include or exclude files based on pattern matches (like /html/); even on multiple pattern matches (say /html/ and /cgi/) across multiple directories.
Then a problem arose. In trying to use pattern matches i came up with this:
# $temp was already defined, i just initialize its value here 1: my (@temp, $in, $out); $temp = ''; 2: 3: PROCESS: while ($temp = shift @files) { 4: $temp = $dir.'/'.$temp; 5: 6: (-f $temp)?(push @temp, $temp):(next PROCESS); 7: IN: foreach $in (@include) { 8: last IN if ($temp =~ eval $in); 9: pop @temp if ($in eq $include[$#include]); 10: } 11: OUT: foreach $out (@exclude) { 12: next OUT if ($temp !~ eval $out); 13: (pop @temp and last OUT) if ($temp =~ eval $out); 14: } 15:} 16:@files = @temp;
jynx
ps: example of use:
perl changeText --include /html/ --exclude /shtml/ s/ome/pattern/g
(Assume default directory is `.')
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Including and Excluding with Impunity
by chromatic (Archbishop) on Nov 13, 2000 at 09:37 UTC | |
|
RE: Including and Excluding with Impunity
by mwp (Hermit) on Nov 13, 2000 at 06:27 UTC | |
|
Re: Including and Excluding with Impunity
by snax (Hermit) on Nov 13, 2000 at 21:17 UTC | |
by jynx (Priest) on Nov 13, 2000 at 23:14 UTC |