Please help this lost soul,
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;
This code pops off
every value! In other words the
eval $out (line 13 above) always returns true (at least in my testing). Whenever i ran it there
would be no files left in @temp or @files at the end of the
while loop. The logic should be correct (albeit i'm not sure on
this point) and there don't seem to be any glaring errors from
my point of view. Please help.
jynx
ps: example of use:
perl changeText --include /html/ --exclude /shtml/ s/ome/pattern/g
(Assume default directory is `.')
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.