I had a chat with my neighbor who asked me if
Padre is going to be able to suggest better code constructs. His example was that some tools can sometimes recognize when a loop is unnecessary in a piece of code. I told him that it is very difficult in Perl and we already have Perl::Critic but I thought about this a bit more and came up with a few examples that I don't think Perl::Critic or any of its extensions covers but might be interesting and possible to recognize.
my $x;
foreach $x () {}
Here I'd suggest to write it as
foreach my $x () {}
and would explain that the $x outside the foreach loop is different from the one inside.
A more involved example would be
@files = `ls`;
and its bigger brother:
@files = `ls *.xml|more`;
In such code I'd suggest to use
glob("*.xml")
Yet another example would be the extensive processing of values from @ARGV that could be replaced by the use of Getopt::Long.
Is there any module on CPAN that can already recognize such constructs and recommend something else?
Can this be done in a reasonable way?
What other constructs would you like to catch and what would you suggest instead of them?
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.