Syntactic Confectionery Delight | |
PerlMonks |
Re: Compactnessby VSarkiss (Monsignor) |
on Jan 11, 2002 at 03:55 UTC ( [id://137870]=note: print w/replies, xml ) | Need Help?? |
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 Section
Meditations
|
|