I was reading some older posts today (having come to PM only recently) and came across this snippet from Jeffa:
use strict; my $array = new list qw(foo bar); my $list = new list qw(baz qux); $array += $list; print "@$array\n"; package list; use overload "+=" => sub { push @{$_[0]},@{$_[1]};$_[0] }; sub new { my $class = shift; my $self = [@_]; return bless $self, $class; }
Where he redefined += to mean combine arrays. Now, my question is as follows:
Can I use the same type of programming to change my method calls from object->method() to object.method() ?
Honestly, I'm sure its not bright to do so for reasons of other people maintaining my code ... but it would make *me* happier when I work on purely personal projects.
And of course I could switch the -> to mean concatinate, which in some ways makes sense ....
I don't need to see code samples of 'how to' or anything ... cause I'd rather puzzle it out myself ;-) ... but I'm wondering if its even possible, and if it is, what issues should I be aware of? (Other then non-standard syntax that could mess up other people).
Thank you kind monks for your wisdom, opinions, or bashing. :-)
-Erik
In reply to Overloading operators: -> to . by theAcolyte
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |