It's not just terseness, it's also that the pieces in Perl fit together. In many other languages I use, I end up with clunky constructs because, for example, a particular statement doesn't evaluate its arguments, and there's no magic "yes, do it now" switch.

Case in point: some code I wrote today has to rewrite a SQL template based on data returned from another query. I have to form a comma-separated list of the values in the first column of the result set, and I need to preserve the original template. (It's an SQL in clause; before I get brow-beaten, I should mention I'm working under "sociological" restrictions.)

Here's what I wrote (paraphrased): ($sql = $templ) =~ s/#LIST#/join ',', map { $_->[0] } @res/e;It's not golf, it's just a nice fit.

I'd be willing to type longer strings to get this, but the fact that I can feed map to join and use it on the RHS of a substitution makes me smile! I shudder to think what I'd have to do to achieve the same thing in, say, VBScript (to pick a particularly nasty example).


In reply to Re: Compactness by VSarkiss
in thread Compactness by FoxtrotUniform

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.