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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.