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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.