I'm glad you picked argument passing as your example, since the ugliest piece of bad Perl I've ever seen(Hey, two out of three ain't bad) is argument passing.

I was beginning to maintain an out-of-house piece of Perl, and was happily reading through it sorting the small pile of wheat from the large pile of chaff when suddenly I hit a brick.

The programmer had, I think, intended to get the kind of default arguments that hashes can easily provide.. but had tried to do it without any kind of hash. They also had odd argument ordering, with related arguments randomly places around the sequence so often the value you needed to default would be in the middle of the 'full' list. I think they were just adding new items to the end as they became required.

I'm now in a new job, so I can't get this code to show you, but here's the essence of how it worked. I'm refusing to comment this, for those Initiates of Perl who can't work out how this works think yourselves lucky and go and reread the hash method.

And yes, the 'use strict' and -w bits were added by me for my example. They didn't use these either, oddly enough.

#!/usr/bin/perl -w use strict; DoStuff (1,2,3); DoStuff (1,3); DoStuff (2); sub DoStuff { my ($a, $b, $c) = (-1, -2, -3); if ($#_ == 2) { ($a, $b, $c) = @_; } elsif ($#_ == 1) { ($a, $c) = @_; } elsif ($#_ == 0) { ($b) = @_; }; print "A= $a\n"; print "B= $b\n"; print "C= $c\n"; }

I'm thankful not to be in that job anymore.

Other bits of wonder I've seen..

I love maintaining the code of people who don't really know Perl, it's ingenious some of the things they can get up to.


In reply to Re: Perl aesthetics: the good, the bad, the ugly. by Molt
in thread Perl aesthetics: the good, the bad, the ugly. by vladb

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.