On Nov 6, 6:08 pm, [EMAIL PROTECTED] (Chas. Owens) wrote:
> On 11/6/07, Ab <[EMAIL PROTECTED]> wrote:
> snip> Now, The thing I am trying to achieve is to call abhinav::test::test2
> > on the runtime.
> > ie, I am passing the value 'abhinav::test::test2' in a variable, and
> > trying to exec in the code below, and this place I am failing.
> > Can someone help me as to how to achieve this in runtime.
>
> snip
>
> The String version of eval is the wrong method to choose.   If you
> want to execute functions at runtime you want a dispatch table.

Be aware that although using a hash a dispatch table is often the
right way to do it if your dispatch table ends up looking like this..

> my %dispatch = (
>     'abhinav::test::test1' => \&abhinav::test::test1,
>     'abhinav::test::test2' => \&abhinav::test::test2,
> );

..where it will always list _every_ function in bhinav::test:: and
_nothing_ else you really should consider if there a genuine reason
that you are not using the symbol table directly as your dispatch
table.

my $dyna_sub = 'test2';
my @arr = ([1, 2], [3, 4], [5, 6], [7, 8]);
my $arr = do { no strict 'refs'; "abhinav::test::$dyna_sub"->(@arr) };

Please see numerous previous threads on this exact same subject for
arguments for and against symrefs in this context. Note: you will,in
fact, find very few arguments against using symrefs in _this_ context.
Mostly you'll find (valid) arguments against using symrefs in some
(most) _other_ contexts then a conceptual leap[1] to infer they must
be bad in this context too.

[1] aka non-sequitur



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to