in reply to Clarifying the Comma Operator

I tried to update my post in previous thread, but there were some problems. I'm not sure presentation is correct and for some reason the server won't let me edit my post yet again. I don't know why. I probably generated something un-parseable for the markup language by pure accident.

Anyway this wording, "The "=>" operator is a synonym for the comma, but forces any word... would appear to me to mean that somehow => and "," are different? I don't think so. Maybe and is the right conjunction?

Replies are listed 'Best First'.
Re^2: Clarifying the Comma Operator
by ig (Vicar) on Jun 07, 2009 at 00:12 UTC

    This is an interesting point.

    I looked at toke.c in the perl source and found that OPERATOR(',') is generated for both "," and "=>". I jumped to the conclusion that they must be identical. But then I tried the following:

    use strict; use warnings; use Data::Dumper; use constant FOO => "something"; my %h = ( FOO => 23, FOO , 24 ); print Dumper(\%h); __END__ $VAR1 = { 'FOO' => 23, 'something' => 24 };

    So they are in fact different, despite the same token being returned from toke.c. Something higher up must look again at what the input text was to decide what to do, but I don't know where this happens.

    update: The distinction is in toke.c, not when scanning "," or "=>" but when scanning a word. After scanning a word, toke.c looks ahead and, if it sees "=>" it returns TERM(WORD).

      Yes, this is interesting as "=>" and "," are not interchangeable. The net of this is that this question is one heck of a lot more complex than it sounded at first!

      If thing X is described as a "delta" from thing Y ("but"). Is Y well defined? And is it possible to clearly understand what X will do even given that you understand Y? (e.g what the "but" delta means).

      As another thought, if defining the complete behavior is too complex, is there some subset that can be described that would be generally useful?

      Sorry for interrupting, May I know what is meant by TERM?

      --Lakshmanan G.

      The great pleasure in my life is doing what people say you cannot do.


        TERM is one of the macros defined and used in the perl source file toke.c. This macro is used to return lexical tokens which are terms in an expression.

        The subroutines in toke.c constitute the perl lexical analyzer. They are called by the parser to obtain a sequence of tokens from the source of the Perl program being interpreted.

        TERM(WORD) returns a WORD token.

Re^2: Clarifying the Comma Operator
by JavaFan (Canon) on Jun 07, 2009 at 00:08 UTC
    Well, => and , are different. The difference is exactly the but part.