Function definition: Difference between revisions

→‎{{header|Perl}}: example with signatures
(→‎{{header|Perl}}: simpler example and more info)
(→‎{{header|Perl}}: example with signatures)
Line 481:
}</lang>
The above subroutine checks whether it was called with exactly two [http://perldoc.perl.org/perldata.html#Scalar-values scalar values] (two dollar signs in the signature) but those values may be not numbers or not even defined. The <code>@_</code> array is unpacked into <code>$a</code> and <code>$b</code> lexical variables, which are used later.
 
The arguments can be automatically unpacked into lexical variables using the [http://search.cpan.org/perldoc?signatures signatures] module:
<lang perl>use signatures;
sub foo ($x, $y) {
return $x + $y;
}</lang>
 
=={{header|Perl 6}}==
Anonymous user