yogibimbi has asked for the wisdom of the Perl Monks concerning the following question:
This produces the following output:use Data::Dumper; my $N = Value->new(23); warn Dumper($N * 2); warn Dumper($N*= 2); my $test; $test->{obj} = $N; warn Dumper($N * 2); warn Dumper($N*= 2); package Value; use overload ('*=' => 'mulSet'); use overload ('*' => 'mul'); sub new { my ($class, $value) = (shift, @_); $class = ref($class) || $class; my $self = {value => $value}; return bless $self, $class; } sub mul { my ($self, $num) = @_; return $self->new($self->{value} * $num); } sub mulSet { my ($self, $num) = @_; $self->{value}*= $num; return $self; }
However, if I comment out either one of the following lines$VAR1 = bless( { 'value' => 46 }, 'Value' ); $VAR1 = bless( { 'value' => 46 }, 'Value' ); $VAR1 = bless( { 'value' => 92 }, 'Value' ); Operation "=": no method found, argument in overloaded package Value at /bla/bla/bla/test/Value.pl line 12.
or the$test->{obj} = $N; use overload ('*=' => 'mulSet');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: overload conflict between * and *= (as an example)
by tobyink (Canon) on Feb 25, 2012 at 13:42 UTC | |
by yogibimbi (Initiate) on Feb 27, 2012 at 17:24 UTC | |
by tobyink (Canon) on Feb 27, 2012 at 18:13 UTC |