Joel wrote:
>
Can you tell me the sequence of events that happen (internally in perl
during parsing) for the following code:

sub fun
{
        print @_;
}

fun fun (1), fun 2, fun (3);

I am particularly interested in the comma operator, in the above code,
as I understand it
(1) first the list operations (which have highest precedence because
of parantheses) will execute first printing "13".
(2) then the comma between fun(1) and fun 2 is evaluated, once this
happens, is the list operation ( fun 2, fun(3) ) evaluated or is the
comma between 2 and fun(3) evaluated?

I suspect you are forgetting that fun() itself returns the success
status of the print() function, introducing additional 1s into the
output. Look:

  local $" = ',';

  sub fun {
    print "fun(@_) ";
  }

  fun fun ('a'), fun 'b', fun ('c');

**OUTPUT**

  fun(a) fun(c) fun(b,1) fun(1,1)


The line

  fun fun ('a'), fun 'b', fun ('c');

parses as

  fun(fun('a'), fun('b', fun('c')));

and each parameter list is evaluated from left to right, hence the order
shown by the code's output.

HTH,

Rob



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


Reply via email to