perlmeditation
merlyn
In response to a P5P posting, I strolled through [perlfunc] and came up with a representative list of the scalar context return values for things we normally use in a list context. Surprisingly, more things <i>don't</i> return a length than do. Here's the list:
<center>
<table border=1>
<tr><td>grep</td><td>length</td></tr>
<tr><td>map</td><td>length</td></tr>
<tr><td>@foo</td><td>length (efficiently)</td></tr>
<tr><td>keys/values</td><td>length (efficiently)</td></tr>
<tr><td>split</td><td>length, but @_ side-effect</td></tr>
<tr><td colspan=2> </td></tr>
<tr><td>(10, 20, 30)</td><td>last element</td></tr>
<tr><td>@foo[3..5]</td><td>last element</td></tr>
<tr><td>(10, 20, 30)[2, 1]</td><td>last element</td></tr>
<tr><td>splice</td><td>last element</td></tr>
<tr><td colspan=2> </td></tr>
<tr><td>caller</td><td>package name (first element of list return)</td></tr>
<tr><td>each</td><td>key (first element)</td></tr>
<tr><td>getpwuid</td><td>username (first element)</td></tr>
<tr><td>getpwnam</td><td>user ID (<i>third</i> element of list return)</td></tr>
<tr><td>glob/<*></td><td>"next" item (repeat until undef)</td></tr>
<tr><td>gmtime/localtime</td><td>printable string (instead of list of components)</td></tr>
<tr><td>readline/<HANDLE></td><td>"next" item (repeat until undef)</td></tr>
<tr><td>readpipe/``/qx</td><td>one item instead of list of lines</td></tr>
<tr><td>readdir</td><td>"next" item (repeat until undef)</td></tr>
<tr><td>reverse</td><td>string reverse instead of list reverse</td></tr>
<tr><td>select(4-arg)</td><td>$nfound (first element of list)</td></tr>
<tr><td>sort</td><td>undef</td></tr>
<tr><td>stat</td><td>success value</td></tr>
<tr><td>times</td><td>$user (first element)</td></tr>
<tr><td>unpack</td><td>first element</td></tr>
</table>
</center>
<div class="pmsig">
<div class="pmsig-9073">
<p>-- [http://www.stonehenge.com/merlyn/|Randal L. Schwartz, Perl hacker]
<br>
Be sure to read [id://205373|my standard disclaimer] if this is a reply.</p>
</div></div>