On Wed, Apr 9, 2008 at 12:14 PM, James Carman &lt;<a href="mailto:developer@peelle.org">developer@peelle.org</a>&gt; wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hey all,<br>
<br>
Is it possible to do something like:<br>
<br>
<br>
&amp;param_test(&quot;somestring&quot;, &quot;another_string&quot; $arrayref);<br>
<br>
sub param_test($tom; $george; @$array) {<br>
 &nbsp; &nbsp; print $tom;<br>
 &nbsp; &nbsp; ....;<br>
}<br>
<br>
<br>
#################<br>
I am wanting to Specifiy how many arguments to take. Also I want to specify the name of the arguments. And also if possible the type of the arguments.</blockquote><div><br>Perl&#39;s concept of a subroutine prototype is unusual and there are some purists who will tell you to never use them. I think they are helpful when used carefully. In this case, this is about the best you can do:<br>
<br>sub param_test($$\@) { <br>&nbsp;&nbsp;&nbsp; my ($tom, $george, $array_param) = @_;<br>&nbsp;&nbsp;&nbsp; ...<br>}<br><br>You would then call the subroutine (make sure you *don&#39;t* use &amp;param_test() or Perl will ignore the prototype):<br><br>
param_test(&quot;somestring&quot;, &quot;otherstring&quot;, @array);<br><br>The other alternative would be to declare param_test() like this:<br><br>sub param_test($$@) {<br>&nbsp;&nbsp;&nbsp; my ($tom, $george, @array_param) = @_;<br>&nbsp;&nbsp;&nbsp; ...<br>
}<br><br>This could be called exactly the same way as before. The significant difference between the two is that in the first one, the $array_param variable is actually a references to the \@array passed, which means you can modify it in place. In the second case, you don&#39;t have a direct reference to the @array value to modify.<br>
<br>The good thing is that if you call param_test() this way, it will warn you during compile that something isn&#39;t right when you try to use it without three parameters, specifically two scalars followed by an array.<br>
<br>That&#39;s about it for compile time checking. For more details, you can see the &quot;Prototypes&quot; section of perlsub (<a href="http://search.cpan.org/search?query=perlsub&amp;mode=all">http://search.cpan.org/search?query=perlsub&amp;mode=all</a>). If you want robust runtime checking, I second Andy&#39;s recommendation of Param::Validate.<br>
<br>Cheers,<br>Andrew<br></div></div>