in reply to Inline::* and string eval -- Have I found a place where it might actually be necessary?

You could use symbolic code references in place of your eval sting (in blocks where you turn off strict refs). Unfortunately, that doesn't really solve your issue and still results in more code. It does bookend your statements and should be clearer for maintenance. You could also just create a code ref for your run routine and then pass it arguments later to decouple, a la

my $code; my $sub_ref = 'sample'; #my $sub_ref = "Lua::$module::$funcname"; { no strict 'refs'; $code = \&{"sample"}; } my @args = (1,2,3); print $code->(@args); sub sample { return shift @_; }

  • Comment on Re: Inline::* and string eval -- Have I found a place where it might actually be necessary?
  • Download Code

Replies are listed 'Best First'.
Re^2: Inline::* and string eval -- Have I found a place where it might actually be necessary?
by Luftkissenboot (Novice) on Dec 26, 2008 at 05:57 UTC

    Aha, brilliant! That was the syntax for reaching into the package symbol table that I couldn't quite wrap my mind around.

    I ended up having to use: my $sub = \&{"Lua::${module}::${funcname}"}; though, of course, to separate the :: from the variable names. So, that's one string eval gone!

    Thank you.

      It can also be done via %::
      \&{ $::{'Lua::'}{$module.'::'}{$funcname} };

      but no strict 'refs'; is a lot easier.

      By the way, Module::Pluggable is now part of core. I'd use that over playing with the symtab if applicable.

        Aha, the first code snippet explains the syntax errors I was getting, thanks.

        I don't think Module::Pluggable will be applicable here, because of the way Inline works, but it's useful to know it's in core now, as I think I can find a use for it elsewhere :-)