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.

<radiant.matrix>
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

In reply to Re: How do you define "elegant"? by radiantmatrix
in thread How do you define "elegant"? by Mutant

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.