Hello Leon, Monday, November 26, 2001, 12:15:59 AM, Leon wrote:
L> ----- Original Message ----- L> From: "Jenda Krynicky" <[EMAIL PROTECTED]> L> To: <[EMAIL PROTECTED]> L> Sent: Monday, November 26, 2001 4:44 AM L> Subject: Re: @_ >> 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 L> I like your style, in fact I think everybody should follow Jenda's style of L> giving an example after an explanation ; an example paints a thousand words. >> numbers you can write it either as >> sub add { >> my ($a, $b) = @_; >> return $a + $b; >> } L> On the above, so what is @_? L> @_ = ? if i have code like: $result = add( 2, 3 ); then in the code sub add { my ($a, $b) = @_; return $a + $b; } @_ is set to the list (2, 3) just after the "sub add {" line there's nothing really special about @_, it's the same as any other array, eg: @foo = (1, 2, 3); isn't special, @_ is just an array who's name is "_", think of the _ like the letter "a" and it might look more comprehensible. the only special part comes when we're calling a subroutine, where @_ is used to pass the variables into our subroutine. we could say: my @foo = (1,2,3); my ($value1, $value2, $value3) = @foo; and now $value1 == 1, $value2 == 2 and $value3 == 3. so it's the same when we use @_ at the start of a function. my ($a, $b) = @_; does that make it any clearer? -- Best regards, Daniel mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]