Joel wrote:
 when calling functions, we need not include parantheses, and we're
still able to pass a list..
like for eg:
my_function "foo", "bar";  #this copies foo and bar into @_ of
my_function.

but alternately the same assignment like @_ = "foo", "bar";
will omit "bar" from the list.. why is this?

That is the way that the comma operator works. "foo" is evaluated and then discarded and then "bar" is evaluated and the result returned. Because the comma operator has lower precedence then the assignment operator you have to enclose the right hand side in parentheses;

@_ = ( "foo", "bar" );


In the case of:

my_function "foo", "bar";

my_function is a list operator which has a very low precedence so the parentheses are not required.


perldoc perlop
perldoc perlsub



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to