Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>edg is correct, but the original code is unnecessarily obtuse. In most cases, <code>$#foo</code> is a red flag that the code could be written more simply using <code>scalar @foo</code>.</p> <pre><code>return (undef) unless ($#ret &gt;= 0); </code></pre> <p><code>unless foo &gt;= bar</code> is difficult to puzzle out. First, turn it into a positive statement.</p> <pre><code>return (undef) if ($#ret &lt; 0); </code></pre> <p>When is $#ret &lt; 0? When it's -1. A $#ret of -1 is an array of length 0. So the above can be written much more simply as...</p> <pre><code>return (undef) if scalar @ret &lt;= 0; </code></pre> <p>But you can't have a negative length array, so...</p> <pre><code>return (undef) if scalar @ret == 0; </code></pre> <p>And == is in scalar context, so that "scalar" is redundant...</p> <pre><code>return (undef) if @ret == 0; </code></pre> <p>But that's just a wordy way of saying "if <code>@ret</code> is false".</p> <pre><code>return (undef) if !@ret; </code></pre> <p>Which I think for simple statement modifiers is better expressed with unless.</p> <pre><code>return (undef) unless @ret; </code></pre> <p>Isn't that easier to follow?</p> <p>As a final side-note, <code>return undef</code> is discouraged because it does the wrong thing in list context. You get back a list containing one undef element, which is true. Instead, just use a blank return which returns undef in scalar context and an empty list in list context.</p> <pre><code>return unless @ret; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload