Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoking a Perl method

Tags:

perl

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 "->".

like image 978
Johannes Ernst Avatar asked Jul 24 '26 08:07

Johannes Ernst


1 Answers

Sounds like you want

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

$pkg->$method;
like image 65
friedo Avatar answered Jul 26 '26 07:07

friedo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!