How can I use send tables in Perl?

Possible duplicate:
How to implement send tables in Perl?

I have a hash table containing commands like int (rand ()), etc. How to execute these commands?

+3
source share
2 answers

You can use eval($str)to execute Perl code that you store in a string variable $str. You can also save your code as function references in a hash, so:

$hash{'random'} = sub { int(rand()) }; 

That way, you can write $hash{'random'}->()to execute a function whenever you want to get an arbitrary value.

See also Embedding send tables on PerlMonks.

+5

, eval. , eval , , .

, ( , , , eval)., , Perl . WHILE .

+1

Source: https://habr.com/ru/post/1725717/


All Articles