in reply to Re: method invocation syntax at perl
in thread method invocation syntax at perl

Thanks a large. This exactly thing i want.
for my case it will be:
print $l->${\($str.$str1)}($str2);
But why don't you recomend this solution?

Replies are listed 'Best First'.
Re^3: method invocation syntax at perl
by Fletch (Bishop) on Jan 03, 2008 at 14:34 UTC

    For one thing if the two strings are coming from an outside source you've just given them a means to call an arbitrary method in your code; granted it's not a gaping hole, but that's generally enough to raise the hackles of the security conscious.

    That aside, there's also no error checking so if anything does go wrong you merely get the generic "unknown method" error message. Better would be to explicitly validate that it's an allowed method name (either through a dispatch table or hash of valid method names, or at the least through using $obj->can( $method_name ) to check that the method will be callable). If it's not then you can explicitly print your own error message with the two distinct parts of the method name (so you don't have to go diving through the debugger to try and determine if someone tried to call with "xxy4" and "4", or "xxy" and "44", or "xx" and "y44", or . . . ).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Thank you very match. As i says it's just an example, but i will add some more security checks using your advice.
      Thanks again.