Johannes Ernst
Johannes Ernst

Reputation: 3176

Invoking a Perl method

This works:

A::B->new();

This doesn't:

my $m = 'A::B->new';
&{\&{$m}};

How can I make it work? The strange syntax does work for regular functions not containing "->".

Upvotes: 3

Views: 68

Answers (1)

friedo
friedo

Reputation: 66937

Sounds like you want

my $pkg = 'A::B';
my $method = 'new';

$pkg->$method;

Upvotes: 4

Related Questions