Perl passing argument into eval
        Posted  
        
            by 
                ehretf
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by ehretf
        
        
        
        Published on 2012-10-03T21:29:21Z
        Indexed on 
            2012/10/03
            21:37 UTC
        
        
        Read the original article
        Hit count: 301
        
I'm facing an issue using eval function.
Indeed I have some function name inside a SQL database, my goal is to execute those functions within perl (after retrieve in SQL).
Here is what I'm doing, considering that $RssSource->{$k}{Proceed} contains "&test" as a string retrieved from SQL:
my $str2 = "ABCD";
eval "$RssSource->{$k}{Proceed}";warn if $@;
sub test
{
   my $arg = shift;
   print "fct TEST -> ", $row, "\n";
}
This is working correctly and display:
fct TEST ->
However I would like to be able to pass $str2 as an argument to $RssSource->{$k}{Proceed} but I don't know how, every syntax I tried return an error:
eval "$RssSource->{$k}{Proceed}$str2"
eval "$RssSource->{$k}{Proceed}($str2)"
eval "$RssSource->{$k}{Proceed}"$str2
eval "$RssSource->{$k}{Proceed}"($str2)
May someone tell me how to properly pass an argument to the evaluated function?
Thanks a lot for your help
Regards.
Florent
© Stack Overflow or respective owner