I was reading an old post by gargle, which links to the Jargon File. Naturally, I went to the entry for Perl, where I read:
Though Perl is very useful, it would be a stretch to describe it as pretty or elegant; people who like clean, spare design generally prefer Python.
I don't really like to participate in language wars, but I've always considered Perl to be one of the more elegant languages. Browsing to the Jargon File's definition of elegant, I found:
Combining simplicity, power, and a certain ineffable grace of design.
(Which, in my opinion, could be a Perl motto!)

Elegance in programming to me is about expressing actions (commands, statements, etc.) in a simple and coherent way. Perl's TIMTOWTDI-ness is (to me) the ideal tool for this.

One example for me in Perl is map. If I have a list of things, and I want to transform them all in some (fairly simple) way, it makes sense to do it all in one line. That is, I would define:
@foo = map { '%'.$_.'%' } @foo;
as more elegant than:
my @new_foo; foreach my $a_foo (@foo) { $a_foo = '%'.$a_foo.'%'; push @new_foo, $a_foo; } @foo = @new_foo;
I'm not just talking about reducing line count, however. If we were doing 10 different things to the items in @foo, and some of them depended on what the individual item was, it would be inelegant to use map, and more elegant to use foreach.

Still, I feel like there's much more to elegant code. There's certainly a "prettiness" factor. I sometimes just have a feeling that this is the "right" way to do it. And I can't really define it any more scientifically than that.

To me Perl allows us to be elegant, simply by offering us many different ways to do something. Of course, this also gives us the opportunity to be even less elegant than other languages, but that seems to be the trade-off with many things in Perl.

In reply to 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.