We don't bite newbies here... much | |
PerlMonks |
Worse Than Regexesby Dominus (Parson) |
on Dec 15, 2001 at 00:57 UTC ( [id://132074]=obfuscated: print w/replies, xml ) | Need Help?? |
If anyone ever tells you that regex syntax is the world's
most unreadable embedded language, you can tell them it's not true.
The Common Lisp format utility is worse. It's analogous to sprintf, only much much more powerful. And unreadable. Perl has \U and \L and \u for changing the case of parts of an interpolated string. format has features like that also. format also has features for doing column justification. And automatic pluralization. And recursively calling a sub-format. And loops. Here's an example from <cite>Common Lisp: The Language<cite>: What's going on here? ~% means to start a new line. ~3@T means to tabulate over three spaces from the current position. (~3T would have meant to move to absolute position 3.) ~V@T is like ~n@T, except that inspead of moving over a specific number of spaces, the argument list of format is consulted for the number of spaces to move---in this case, the value is (+ *ctl-index* 3) spaces. ~A means to insert a string, in this case the value of *ctl-string*. ~? means to make a recursive call to format, using the format string in string, and the argument list in args, and insert the result. Here's another delightful example from the same place: I won't explain this. But I will say that ~:[...~] is like a miniature switch statement, and ~:{...~} is like a miniature for loop, and ~:^ is like last. For a complete description of format and an explanation of the examples in this note, see here. I recommend it. It has to be seen to be believed.
Now, dare I suggest that someone should write a Perl module that formats strings the way Common Lisp format does?
--
Back to
Obfuscated Code
|
|