On 6/1/07, <b class="gmail_sendername">Ricardo SIGNES</b> &lt;<a href="mailto:rjbs-perl-abe@lists.manxome.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">rjbs-perl-abe@lists.manxome.org</a>&gt; wrote:
<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
* &quot;Faber J. Fedor&quot; &lt;<a href="mailto:faber@linuxnj.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">faber@linuxnj.com</a>&gt; [2007-06-01T12:25:22]<br>&gt; I don&#39;t think this is what Larry, et. al had in mind when they wrote the
<br>&gt; parameter passing routines in Perl, but this works for me.&nbsp;&nbsp;I&#39;m just
<br>&gt; wondering if there are any hidden gotchas:<br><br>I think you&#39;re wrong. ;)&nbsp;&nbsp;The things you&#39;re talking about have a lot to do with<br>the kind of list flattening, stack passing parameter style in Perl 5.<br>

<br>I don&#39;t know Larry&#39;s intent, but I think that you think this is a bad idea on<br>levels on which it isn&#39;t...</blockquote><div><br>Au contrair!&nbsp; I deduced that it would work from basic principles (&quot;If Perl flattens it the way I understand it, then this will work...&quot;) and thought it Way Cool when it did. However, since I haven&#39;t seen that idiom anywhere, I assumed there was a Rule Against It.
<br>&nbsp;</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">&gt; I&#39;ve got a func that returns the min and max values in an array:<br>

<br>Nitpick:&nbsp;&nbsp;subroutines never return arrays.&nbsp;&nbsp;They return scalars or lists.&nbsp;&nbsp;A<br>list is an immutable sequence of data, an array is a container that holds a<br>mutable sequence.&nbsp; </blockquote><div><br>Which is why I can&#39;t do 
<br><br>(@MinY, @MaxY) = getMinMax(@foo)<br><br>because Perl can&#39;t tell where to split the arrays I&#39;m returning, right? <br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

get used to thinking about<br>it correctly, and someday you will not make a mistake that you might have<br>otherwise made.</blockquote><div><br>I don&#39;t need that lecture, you whippersnapper! :-) it&#39;s one of my guiding principles and something I impress on my students. 
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Here&#39;s the thing, though.&nbsp;&nbsp;I would probably pass a reference in,</blockquote>

<div><br>I prolly would too, but this was a serendiptous discovery during refactoring.<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

See, if you say, now, &quot;get_min_max takes a list of data to minmax&quot; then you can<br>never, ever change the specifics, because you can&#39;t add more parameters:&nbsp;&nbsp;any<br>parameter you add is by definition part of the list of data.
<br><br>There are two solutions:&nbsp;&nbsp;(1) Later, declare that some sort of datum is magic in<br>the last value (well, if the last value is a hashref, it&#39;s actually options),<br>but this can be a real pain in the butt.&nbsp;</blockquote>

<div><br>and it&#39;s tacky, too!<br>&nbsp;</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">&nbsp;(2) Always pass in an arrayref,<br>therefore creating a definition for the semantics of only one parameter.
<br>Later, you can say that the second param modifies the routine&#39;s behavior in<br>some way.</blockquote><div><br>&nbsp;</div>Then I don&#39;t grok the technique here.&nbsp; If I modified my original code to use an array ref, the code would look like this:
<br><br>sub getMinMax {<br>&nbsp;&nbsp;&nbsp; my ($data) = @_ ;<br>&nbsp;&nbsp;&nbsp; my $stat = Statistics::Descriptive::Full-&gt;new(); # a great stats package!<br>&nbsp;&nbsp;&nbsp; $stat-&gt;add_data(@$data);<br>&nbsp;&nbsp;&nbsp; return ($stat-&gt;min(), $stat-&gt;max());<br>
</div>}<br><br>I don&#39;t see how to get/use a second parameter in the arrayref.<br><br>--<br><br>Faber<br><br>