Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Previously unseen error in connection with -X functions

by JavaFan (Canon)
on Oct 31, 2008 at 11:25 UTC ( #720679=note: print w/replies, xml ) Need Help??


in reply to Previously unseen error in connection with -X functions

Now, I don't even know if this is a proper SoPW since I understand that, to put it simply, "something strange happens with these strangely named functions, even if the docs say that they apart that detail they're not different from any other unary operator..."
Since you cannot override operators (although you can overload certain operations - but said overload magic hangs off the operand, not the operator itself), it isn't surprising you cannot override -e. Note also that the error message you get you also get if you replace '-e' with '+', 'cmp', 'feeble' or any other non-function.

Here's another way to see -e isn't a function:

perl -wce '&-e' Bareword found where operator expected at -e line 1, near "&-e" (Missing operator before e?) syntax error at -e line 1, next token ??? -e had compilation errors.
It wouldn't be a syntax error if -e was a function.

Note also that perlfunc says they are operators:

       -X FILEHANDLE
       -X EXPR
       -X DIRHANDLE
       -X      A file test, where X is one of the letters listed below.  This
               unary operator takes one argument, either a filename, a
               filehandle, or a dirhandle, and tests the associated file to
               see if something is true about it.

Replies are listed 'Best First'.
Re^2: Previously unseen error in connection with -X functions
by blazar (Canon) on Oct 31, 2008 at 13:44 UTC
    Here's another way to see -e isn't a function:

    I personally believe that it's too bad it isn't. Actually, it even seems one, not to mention that its documentation is available under perldoc -f -X! Of course Perl 6 knows better by making all operators actual functions. But I wouldn't dare asking that much in 5's realms: perhaps one difficulty in this sense is the new stacking facility la -f -w -x $file however AIUI from the docs that's just syntax fancy. Which I read in the sense that the parser takes care of it making it into the equivalent of -x $file && -w _ && -f _, but at this point ideally those tests may be overridden and without interfering at all with the additional magic, which would be completely orthogonal.

    --
    If you can't understand the incipit, then please check the IPB Campaign.
      I think one of the reasons -f isn't a function is that it violates the naming rules. Identifier names have to start with letters, and dashes are not allowed. -f violates that. Changing it would probably mean changing the lexer. Which I don't think many people are willing to do.

      perhaps one difficulty in this sense is the new stacking facility la -f -w -x $file however AIUI from the docs that's just syntax fancy. Which I read in the sense that the parser takes care of it making it into the equivalent of -x $file && -w _ && -f _,
      I was under the impression that the stackability was archieved by -f and friends returning magical values. But if there's magic, if doesn't show with Devel::Peek::Dump, so I'm probably wrong in my impression.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://720679]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2021-11-29 21:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?