in reply to Re^2: Implementing named infix operators with parser hook?
in thread Implementing named infix operators with parser hook?

Only just noticed this line of your comment:

I think it doesn't, since I need most operators already. :/

Not sure what you mean by it. Did you assume that using Sub::Infix takes over existing operators, so you can no longer use (for example) the | or / operators normally? Because that's not what it does. You can continue to use the existing Perl operators normally, with no slow down, but Sub::Infix will allow you to define additional operators like:

use Sub::Infix; BEGIN { *between = infix { my ($number, $range) = @_: $number >= $range->[0] and $number <= $range->[1]; }; } if ($value <<between>> [1,10]) { ...; }

The only limitation is that your infix operator can't be spelled just between. It needs to be |between|, /between/, or <<between>> (and depending on which you choose, you'll get different precedence).

Replies are listed 'Best First'.
Re^4: Implementing named infix operators with parser hook?
by LanX (Saint) on Aug 17, 2018 at 12:50 UTC
    Yes you are right, I fell back into my misunderstanding that operators like / are overloaded, while you are making "between" a constant which returns objects blessed with a class with overloaded operators.

    Since / is only overloaded for that class it doesn't interfere with other parsing "objects".

    I doubt it's even possible in Perl to overload operators for unblessed objects like literals or scalar variables.

    (unless using the autobox module which hooks into the compiler via XS.)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice