Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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..

  • Regexps used for XML parsing which also rely on the positions of newlines. Good thing the same company wrote the program which generates the XML really.
  • A nice bug where someone was initialising hashes with '%hash = {}' instead of '%hash = ()' and then wondering why they were getting a nonsense result.
  • A recursive program that executed itself with backticks.
  • Form-driven CGIs which took parameters like "delete * from users where username='eric'", where the eric bit was template-driven as the form was output. The programmer couldn't see why this was a security hole as he knew what he'd printed.

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-23 20:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found