<br><font size=2 face="sans-serif">We are having way too much fun with
this. Good comment on commenting Brian! &nbsp;Yitzchak has appropriately
responded for me. &nbsp;But I think the term &quot;drain&quot;, that I
did not use first, but, none the less has now been twisted. &nbsp;The first
use of the word &quot;drain&quot; in the context of this discussion came
from the shift/pop solution, where the array was prematurely &quot;drain&quot;ed
from the shift, leaving nothing to pop, causing $last to be undefined.
&nbsp;So the term drain was someone else used to describe the emptying
of an array through the use of shift and pop. &nbsp;I pointed out that
the slice solution does not drain anything because it merely accesses two
elements, nondestructively to the array, which in this case was anonymous
and lost anyway. &nbsp;The split, as others have pointed out, had nothing
to do with it, as it only created the array from a string, and was not
being used directly to populate $first and $last.</font>
<br>
<br><font size=2 face="sans-serif"><br>
---<br>
Rick Croote<br>
Software Engineer<br>
Environment and Tools Team<br>
Philips Medical Systems<br>
Bothell, WA<br>
Rick.Croote@Philips.com<br>
Phone: 425-487-7834<br>
</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=33%>
<br>
<br>
<br>
<br>
<br><font size=1 face="sans-serif"><b>Yitzchak Scott-Thoennes</b> </font>
<p><font size=1 face="sans-serif">Sent by:</font>
<br><font size=1 face="sans-serif">spug-list-bounces@pm.org</font>
<p><font size=1 face="sans-serif">2005-06-30 10:49 AM</font>
<td width=66%>
<table width=100%>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td valign=top><font size=1 face="sans-serif">&quot;DeRykus, Charles E&quot;
&lt;charles.e.derykus@boeing.com&gt;</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td valign=top><font size=1 face="sans-serif">spug-list@mail.pm.org</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td valign=top><font size=1 face="sans-serif">Re: SPUG: spug: What is the
idiomatic way &nbsp; &nbsp; &nbsp; &nbsp; toextractfirst/lastitemafter
split?</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Classification</font></div>
<td></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<div align=right>
<br></div></table>
<br>
<br>
<br><font size=2><tt>On Thu, Jun 30, 2005 at 09:28:06AM -0700, DeRykus,
Charles E wrote:<br>
&gt; Ok, I characterized this as a &quot;drain&quot; because, superficially
at<br>
&gt; least, you're filling a bigger bucket with a smaller one. &nbsp;The
split<br>
&gt; output consists of a single item but the Action of the function<br>
&gt; split populates $first with that single item; and then backfills<br>
&gt; $last with an undef. Here's what I assume Rick was referring to in<br>
&gt; claiming that no &quot;drain&quot; occurred:<br>
&gt; <br>
&gt; &nbsp; &nbsp; &nbsp;perdoc -f split:<br>
&gt; <br>
&gt; &nbsp; &nbsp; &nbsp;When assigning to a list, if LIMIT is omitted,
Perl supplies a LIMIT<br>
&gt; &nbsp; &nbsp; &nbsp;one larger than the number of variables in the
list, to avoid<br>
&gt; &nbsp; &nbsp; &nbsp;unnecessary work. <br>
&gt; <br>
&gt; <br>
&gt; &nbsp; &nbsp; &nbsp;perl -MO=Deparse -e '($first,$last) = split(&quot;
&quot;,&quot;foo&quot;);'<br>
&gt; &nbsp; &nbsp; &nbsp;($first, $last) = split(&quot; &quot;, 'foo',
3);<br>
&gt; <br>
&gt; <br>
&gt; The split really generates only 1 element; behind the scenes, split<br>
&gt; orchestrates output so $first gets populated with that 1 element and<br>
&gt; then $last gets backfilled with an 'undef' because the original list<br>
&gt; is exhausted. Maybe that seat-of-the-pants explanation is flawed<br>
&gt; somehow...<br>
&gt; <br>
&gt; I assume Rick felt that because split generates values for both<br>
&gt; $first and $last this shouldn't be thought of as a &quot;drain&quot;.
To me,<br>
&gt; it just seems natural to call it a &quot;drain&quot; because there's
really a<br>
&gt; 1 item output and that's trying to fill 2 slots.<br>
<br>
But the case under consideration isn't ($first, $last) = split ...;,<br>
it's ($first, $last) = ( split ... )[0, -1]; which indeed never leaves<br>
$last undefined. &nbsp;If only one element is produced by split, both<br>
$first and $last get assigned that value.<br>
_____________________________________________________________<br>
Seattle Perl Users Group Mailing List &nbsp;<br>
 &nbsp; &nbsp; POST TO: spug-list@pm.org<br>
SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list<br>
 &nbsp; &nbsp;MEETINGS: 3rd Tuesdays, Location: Amazon.com Pac-Med<br>
 &nbsp; &nbsp;WEB PAGE: http://seattleperl.org/<br>
</tt></font>
<br>