Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Answer: Is there any way I can use object.method() instead of object->method()?

by jeffa (Bishop)
on Aug 11, 2002 at 22:26 UTC ( #189343=categorized answer: print w/replies, xml ) Need Help??

Q&A > object-oriented programming > Is there any way I can use object.method() instead of object->method()? - Answer contributed by jeffa

I searched CPAN for Perl6 and did not find any modules that offer that ability yet. You could do something like:
use strict; my $code = do {local $/;<DATA>}; $code =~ s/(\w)\.(\w)/$1->$2/g; $code =~ s/(?<!\w)_(?!\w)/./g; eval $code; die $@ if $@; __DATA__ my $foo = Foo.new(); $foo.foo('foo'); $foo.bar('bar'); $foo.baz('baz'); print $foo.foo _ "\n" _ $foo.bar _ "\n" _ $foo.baz _ "\n"; package Foo; use Class::MethodMaker new => 'new', get_set => [ qw /foo bar baz / ];
but not only is that twisted (and silly), there is more than likely some usage of . and _ that i missed with the regexes. Best to just stick with the arrow notation - it is only one more character to type, after all ... that or start using Python ... /duck

UPDATE: belg4mit++ for suggesting Filter::Simple - i missed that one ...

  • Comment on Answer: Is there any way I can use object.method() instead of object->method()?
  • Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
Discipulus without Corion and with choroba in another timezone the monastery was silent.. I was silbing alone in the cloister
[choroba]: Yes, I feel alone in the cyberspace...
[choroba]: Not many occasions to talk to my wife, either :-(
Discipulus s/silbing/whistle/ dunno from where this word was in my mind..
[Discipulus]: lost in time in space and in the meaning (rocky horror picture show)
[Corion]: Discipulus: Yeah, a short vacation on the Canary islands (Lanzarote). Always great to be in the warmth and sun, from a cold and rainy February here ;)
[Corion]: choroba: Yeah, you have to find a time for the regular skype (or whatever) meetup, I imagine that's hard

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2017-02-22 08:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (325 votes). Check out past polls.