develooper Front page | perl.perl5.porters | Postings from November 2008

Re: Why are the file test operators in perlfunc?

From:
Moritz Lenz
Date:
November 4, 2008 14:24
Subject:
Re: Why are the file test operators in perlfunc?
Message ID:
4910D9ED.3090304@casella.verplant.org
Michael G Schwern wrote:
> demerphq wrote:
>> 2008/10/31 Michael G Schwern <schwern@pobox.com>:
>>> This came up on #perl recently, why are the filetest operators in perlfunc?
>>> They sure look like unary operators to me.  I wouldn't think to look for them
>>> amongst the functions.
>>>
>>> There's only one mention of them in perlop, and that's this.
>>>
>>>       Regarding precedence, the filetest operators, like "-f", "-M", etc. are
>>>       treated like named unary operators, but they don't follow this func-
>>>       tional parenthesis rule.  That means, for example, that
>>>       "-f($file).".bak"" is equivalent to "-f "$file.bak"".
>>>
>>> Even the perlfunc entry says they're ops.
>>>
>>>       -X FILEHANDLE
>>>       -X EXPR
>>>       -X      A file test, where X is one of the letters listed below.  This
>>>               unary operator takes one argument
>>>
>>> Would anyone be opposed to their docs being moved to perlop?
>> 
>> Change perlfunc to not call them ops. They aren't operators, they are
>> functions, *with* side effects. Calling them operators at all is
>> wrong.
> 
> Why are they functions?  What makes a function and what makes an operator?
> What's the difference between a file test operator/function and a unary operator?

Perl 6's take on this is that an operator is a funnily named function
that also happens to have a precedence level and an associativity.

Since -X is certainly "funnily named" it's an operator ;-)

Moritz




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About