Hi,
Recently I wanted to use some code in a script I wrote so I thought of getting it from CPAN.
I wanted to use something to get cmd arguments and their values and
this seemed nice(it was nice before looking at the source code).
After some time I looked at the module and wondered what could be in.
Covered with curiosity I couldn't resist not pressing the SOURCE CODE link to
see what could lie behind it.
What I found took was a BIG surprise,
IT WAS A COMPLETE AND UTTER PILE OF OVERBLOATED CRAP!
I mean,without any disrespect for the author(which I don't know and hope will not need to anytime soon).
Arguments summary:
- totally unreadable
- too big compared to what it does
- contains hidden "logic" that is NOT documented
I propose the following code which is cleaner and more readable:
11 my $params;
12 while(@ARGV){
13 my $a=shift @ARGV;
14 unless(@ARGV) {
15 $params->{$a}="";
16 last;
17 };
18 if($a =~ /^-/) {
19 my $b=shift @ARGV;
20 unless($b){
21 $params->{$b}="";
22 last;
23 };
24 if($b !~ /^-/){
25 $params->{$a}=$b;
26 } else {
27 $params->{$a}="";
28 unshift @ARGV,$b;
29 };
30 };
31 }
And all these for a simple module !
Update: 20101029 Content restored by Corion
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.