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
In reply to Re: Re: Perl aesthetics: the good, the bad, the ugly.
by agentv
in thread Perl aesthetics: the good, the bad, the ugly.
by vladb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |