Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Compactness

by VSarkiss (Monsignor)
on Jan 11, 2002 at 03:55 UTC ( [id://137870]=note: print w/replies, xml ) Need Help??


in reply to Compactness

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).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://137870]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-03-28 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found