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

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.