in reply to Overloading operators: -> to .

You could probably overload '.' to mean '->', but '->' is not overloadable. Watch out for interaction with '.='. You may not be able to pass arguments to your methods, since '.' only takes two arguments.

Why do this? I don't much approve of the purging of C notation from perl 6, and there seems to be no reason at all for it to spill back into perl 5.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Overloading operators: -> to .
by Abigail-II (Bishop) on Sep 26, 2003 at 08:55 UTC
    You may not be able to pass arguments to your methods, since '.' only takes two arguments.

    Oh, sure you can. You just have to use a trick:

    #!/usr/bin/perl use strict; no warnings; package UNIVERSAL; sub AUTOLOAD { my $method = $UNIVERSAL::AUTOLOAD; $method =~ s/.*:://; return if $method eq "DESTROY"; [$method => @_]; } package DotDotDot; use overload "." => \˙ sub new { bless [] => shift; } sub method { my $self = shift; print "method: @_\n"; } sub dot { my $self = shift; my ($method, @args) = @{+shift}; $self -> $method (@args); } package main; my $obj = DotDotDot -> new; $obj . method (1, 2, 3); __END__ method: 1 2 3

    You may have to fiddle a bit to get inheritance working properly though.

    Abigail