Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Help needed with Perl script designed to find files by extension and count the number of chars

by Athanasius (Archbishop)
on May 01, 2015 at 02:24 UTC ( [id://1125325]=note: print w/replies, xml ) Need Help??


in reply to Help needed with Perl script designed to find files by extension and count the number of chars

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,

  • Comment on Re: Help needed with Perl script designed to find files by extension and count the number of chars
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1125325]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 00:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found