I think it doesn't, since I need most operators already. :/
But thanks for reminding me.
I new it from discussions here, but remembered it differently.
(i.e. the operator needs to be blessed not the operands, which is cool)
| [reply] |
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).
| [reply] [d/l] [select] |
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.)
| [reply] [d/l] [select] |