theAcolyte has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Overloading operators: -> to .
by Zaxo (Archbishop) on Sep 26, 2003 at 03:17 UTC | |
by Abigail-II (Bishop) on Sep 26, 2003 at 08:55 UTC | |
|
Re: Overloading operators: -> to .
by tilly (Archbishop) on Sep 26, 2003 at 03:18 UTC | |
by belg4mit (Prior) on Sep 26, 2003 at 03:37 UTC | |
by theAcolyte (Pilgrim) on Sep 26, 2003 at 04:39 UTC | |
by theAcolyte (Pilgrim) on Sep 26, 2003 at 03:24 UTC | |
|
Re: Overloading operators: -> to .
by Juerd (Abbot) on Sep 26, 2003 at 09:08 UTC | |
|
Re: Overloading operators: -> to .
by jonadab (Parson) on Sep 26, 2003 at 03:11 UTC | |
|
Re: Overloading operators: -> to .
by PodMaster (Abbot) on Sep 26, 2003 at 04:45 UTC |