in reply to not: function or operator?

Good question.

It is documented in perlop, so it theoretically should be an operator. OTOH it certainly works like a function.

It is supposed to be lower precedence than a list operator. At least it is documented that way. So at one point someone had in mind what that was supposed to mean. But I am having some trouble (OK, a lot of trouble) figuring out how to write code that could test for that and demonstrate a difference...

Very specifically, could anyone figure out some sample code that distinguishes between not and my_not after the following code? (Other than the name and games with overrides.)

sub my_not ($) { shift ? "" : 1; }
I certainly can't...

Replies are listed 'Best First'.
Re: Re (tilly) 1: not: function or operator?
by MrNobo1024 (Hermit) on Mar 03, 2001 at 10:32 UTC
    "print not 0, 1" dosen't print anything, but "print my_not 0, 1" prints 11.
      Ah, then it must really be an operator. As you notice, it manages to force its arguments into boolean context. But it does that and takes a whole list of arguments quite cheerfully. How would a function do that?
      "not 0 | 1" is an empty string, but "my_not 0 | 1" is 1.