Hello again Griegomas,
I see you have updated your post to incorporate some of the advice given (but still no strict). In itself, that’s good. However, your re-write of the OP has the unfortunate effect of removing context from the following replies, which makes it hard for monks to follow the thread. For small changes, you can use <strike>...</strike> tags, but for large-scale changes such as this, it would be better to put the update (clearly marked as such) at the foot of the original code. Better still would be to start a new node, since your update includes a new question.
This results in an extension like .h finding all files that end with h.
That’s because the . has a special meaning within a regular expression. To remove that special meaning — in other words, to get whatever text is in $ARGV[0] to be treated literally — you need to enclose the text within the escape sequence \Q ... \E:
12:04 >perl -we "my @files = qw(yes.h noh); for (@files) { printf qq[% +s: %s\n], $_, /$ARGV[0]$/ ? 'match' : 'no match'; }" .h yes.h: match noh: match 12:07 >perl -we "my @files = qw(yes.h noh); for (@files) { printf qq[% +s: %s\n], $_, /\Q$ARGV[0]\E$/ ? 'match' : 'no match'; }" .h yes.h: match noh: no match 12:07 >
See More on characters, strings, and character classes in perlretut.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Help needed with Perl script designed to find files by extension and count the number of chars
by Athanasius
in thread Help needed with Perl script designed to find files by extension and count the number of chars
by Griegomas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |