That is only cleaner if the default function (list1 in this case) is Memoize'able, and reasonably fast (or already memorised). For example, if list1() was really $iter->(), where &$iter was a sub reference that iterated over all possible combinations of some other list. Calling it twice has the side effect of missing every other entry. And you have about a 50% chance of having do_it_right() return an empty list or undef or whatever shows the termination of the iteration from list1() depending on whether the number of combinations is odd or even.

Or, let's say list1() was long-running. e.g., looking data up on a web page, pulling data from a remote database server, finding the time it takes for 4 pings to a server in another country. You don't want to call it twice.

So, yes, for the given sample data (which I thought was obvious that it was merely sample, and not actually representative of real code), you're right, that may work fine. But then you're missing the point of the meditation: the convenience of the || operator in scalar context (each item evaluated once and only once), and how I mistakenly thought that this applied in list context, even though, as brian_d_foy points out, perlop explicitly says not to do it.


In reply to Re^2: Bitten by the || bug by Tanktalus
in thread Bitten by the || bug by Tanktalus

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.