Tests for the “falseness” of the return-value are used in my code only when the value is 1 or 0.
I more or less agree with the rest of what you are saying, but I do not agree with that. It is perfectly legitimate, Perlish and idiomatic to evaluate an array in scalar/boolean context to figure out if it is empty. The scalar return value may be 0 (the array is empty) or 1, 2, 3, ..., any positive integer other than 0 (the array is not empty). For example:
while (@array) { my $val = shift @array; # do something with $val }
or possibly:
while (my $val = shift @array) { # ... }
or:
if (length $string) { # ... }
(but not if ($string), because that might not give the expected result with the string "0"). Or you could have a sub return undef (false) if it did not succeed, or a hash or array reference (something that is always true), or even a simple array or hash, if it did succeed.

Similarly, if you open a file with this idiomatic syntax:

open my $fh, "<", $file or die "failed to open $file $!";
you're not testing for 0 or 1, and yet it works perfectly and is considered to be a best practice.

Of course, you've gotta know what you're doing and should probably try not to be too clever. I once got bitten by something like this:

$error_count++ and next if some_condition();
which did not work correctly the first time through the loop, because $error_count was 0 (or undef, whatever it was, I don't remember, it happened some years ago). While:
++$error_count and next if some_condition();
would have worked fine, I was probably trying at the time to be a little bit too clever (and too concise).

Limiting boolean tests to only 0 and 1 values is taking off a lot of Perl's expressive power.

Update: crossed out one example after the comment below from Anonymous Monk.


In reply to Re^4: How to determine if an array contains an undef value? by Laurent_R
in thread How to determine if an array contains an undef value? by thanos1983

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.