From: "Purshottam Chandak" <[EMAIL PROTECTED]>
> In the following subroutine, I do not understand why we need to use my ($n1,
> @n2) = @_;. Why are we using @_ if it is not used elsewhere. Can somebody
> throw some light on this please?
>
> # max($n1, @n2);
> # Returns the maximum of the arguments.
> sub max {
> my ($n1, @n2) = @_;
> foreach $m (@n2) {
> if ($n1 < $m) {
> $n1 = $m;
> }
> }
> return ($n1);
> }
>
> Pc
When you cann a function all the parameters you gave it end up in
@_. You can (and usualy do) copy them then into some lexical
variables to give them meaningfull names. You don't have to
though. If for example you wanted to write a function that sums two
numbers you can write it either as
sub add {
my ($a, $b) = @_;
return $a + $b;
}
or
sub add {
return $_[0] + $_[1];
}
For now it would IMHO be best if you start all your functions like
this :
sub FunctionName {
my ( $param1, $param2, ..., $paramN) = @_;
Jenda
=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
--- me
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]