in reply to Re: Perl aesthetics: the good, the bad, the ugly.
in thread Perl aesthetics: the good, the bad, the ugly.

...but this is proof not of the ugliness of Perl, but of the ugliness of someone's mind.

Where that person wrote:

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"; }

We might instead write:

sub DoStuff { my ($a, $b, $c) = @_; $a = defined $a ? $a : -1; $b = defined $b ? $b : -2; $c = defined $c ? $c : -3; print "A= $a\n"; print "B= $b\n"; print "C= $c\n"; }

And while this lacks some elegance (for instance, I might want to create a loop that simply tests $_[0] and then shifts the top value into the next of my variables), I think it would be a simple improvement.

The real point is that the language allows us to be ugly. Some of choose to do so.

---v

Replies are listed 'Best First'.
Yeah, except your's is wrong
by Anonymous Monk on May 03, 2002 at 04:24 UTC
    Note that if there are 2 arguments, the original code set $a and $c, not $a and $b.

    -Mike