in reply to How do you define "elegant"?
See, to me, elegance has a lot to do with the expressiveness of the language. I'll use your example:
@foo = map { '%'.$_.'%' } @foo;
That's pretty cool, but not particularly elegant. People familiar with map (which exists in other languages, too) will wonder why you're mapping a copy and then assigning it back to the original array when you could just:
foreach (@foo) { $_ = '%'.$_.'%' }
To me, that's more elegant because it's more expressive. It outright says "for each element in @foo, change it to have '%' on each side". Compare this to the map call, which says "perform this function - add '%' on either side of the parameter - on a copy of each element in @foo, assinging the result back to @foo". That's not elegant, it's complex.
Of course, it's also just my opinion, and doesn't entirely detract from your premise. Things like $_ are one of the reasons I believe that Perl code can be so elegant.
But, I disagree that Perl is inherently elegant. What makes Perl so wonderful, to my mind, is that Perl code truly reflects the programmer: if you're a bad programmer, your Perl code will be ugly; if you're good, then it will be beautiful.
|
|---|