The warning has nothing to do with overloading. You can reproduce it with the core >>:
As the warning says, you are using the operator in a void context. If you use it in a non-void context the error goes away; this is true even for your overloaded operator.% perl -we '$foo = 1; 3 >> $foo' Useless use of right bitshift (>>) in void context at -e line 1.
use strict; use warnings; package Foo; use overload '>>' => 'right_shift'; sub new {bless {}, __PACKAGE__} sub right_shift { print "OK!\n"} package main; my $foo = Foo->new; my $x = "test" >> $foo; __END__ OK!
The root of the problem is that you are trying to turn an operator that normally has no side effects into one that does (and, apparently it is only the side effects of this new operator that you're interested in). (In particular, note that the core >> does not modify its LHS.)
I suppose you can silence the warnings with something like
() = "test" >> $foo;
the lowliest monk
In reply to Re: overloading ">>" generates warning?
by tlm
in thread overloading ">>" generates warning?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |