I happen to like modifiers, such as "do this unless that", or "perform this code foreach of these". But I like them usually when I want the action to seem (to the reader of the code) like the most important part of that statement, and in fact, the default behavior. There are, of course, exceptions to that rule. For example, I see nothing wrong with "
next unless $line; inside a file-reading loop where I've just chomped and want to move on to the next line if this one turned out to be blank. But for the most part, I prefer my modifiers to be all about actions that I want to have happen except for some less common circumstance.
Keeping that in mind, I would change your die "Usage..." unless @ARGV == 2; to a slightly different idiom.
@ARGV == 2 or die "Usage.....";
Now you've got the condition of death right up front so that a reader will see what's triggering the death; too many elements in @ARGV. This is the same approach commonly used with file open. You will find a strong recommendation in that direction for mostly the same reasons I've given in perlstyle. But to be fair, this is a gray area, and you do see it both ways all the time.
I also don't like the notion of setting up aliases to $File::Find::name using typeglobs. These variables are read-only according to the POD for File::Find. When you start aliasing them, you might not remember that $name is special, and shouldn't be modified.
I would much rather just see you checking $File::Find::name directly, or assigning its value to a lexical $name.
The next thing that bothers me is in your $wanted->() sub. You're not checking for the validity of your pattern match, and then you're subsequently relying on $2 to contain a reasonable value. Don't rely on captures unless you're certain that there was a match. Just don't; you will get into trouble eventually with that approach.
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.