The comments of almut and other(s) along the lines of "But why...?" should be heeded.
But if you want to press on regardless, here's a slightly different approach:
>perl -wMstrict -le "package BlaBal; sub hi { print 'hi there ', $_[0] }; sub new { my $class = shift; return bless { test123 => \&hi } => $class; } package main; my $obj = BlaBal->new; $obj->{ 'test' . (120+3) }->('sailor'); " hi there sailor
BTW: The statement
return bless {}, __PACKAGE__;
in the code in Re^4: concat method inside method call does what bless does by default. So the statement
return bless {};
does the same and is 'prettier'! (However, a constructor so defined cannot be used by derived classes, so this is perhaps a bug, or at least a mis-feature.)
In reply to Re: concat method inside method call
by AnomalousMonk
in thread concat method inside method call
by jeanluca
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |