This is a mini-meditation I often felt the need to make, and I probably touched upon the subject several times. Actually, this is taken from a clpmisc post of mine (link @ GG) the relevat portion of which I'm reporting here.
Somebody, in an earlier post, wrote:
Versalitily isn't always a good thing. This might be stretching the realms of funky Perl code, but consider the following two programs that will add two numbers.
My reply is as follows:
Well, you're right. However there's a remark I always feel like making when speaking of Perl's TMTOWTDIness: it's true that there's more than one way to do it. But it's also true that for common situations there is often a preferred way to do it. Or a few preferred ways, with different advantages in different respects. So, if you have e.g. to iterate over a range of numbers "the" WTDI is
for ($MIN..$MAX) { # ...and if you have to iterate over a handle, then "the" WTDI is
while (<$fh>) { # ...Please take all this with a grain of salt, of course.
Perl 6 aims at being even more multiparadigmatic than 5, and to stay at the same time consistent. So thanks to lazy evaluation, you will e.g. both
.say for 1..6; # and .say for =$fh;
Further comments:
In reply to On TMTOWTDIness by blazar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |