In Perl, a symbol ->has two meanings. If it is followed by a single word $obj->nameor scalar $obj->$name, it ->means a method call.
If an ->opening bracket follows instead , it will be dereferenced according to the following table:
$obj->(...)
$obj->[...]
$obj->{...}
-> , perl , , , . , ->( , perl $object_ref , , , .
-> , perl - :
if (reftype $name eq 'CODE') {
$name->($object_ref)
}
elsif (my $code = $object_ref->can($name)) {
$code->($object_ref)
}
else {die "no method $name on $object_ref"}
, :
sub foo {"foo(@_)"}
my $foo = \&foo;
say foo 'bar';
say $foo->('bar');
say 'bar'->$foo;
sub Foo::bar {"Foo::bar(@_)"}
my $obj = bless [] => 'Foo';
my $method = 'bar';
say $obj->bar(1);
say $obj->$method(1);