in reply to eval code generation - parameters & return values
Would anonymous subroutines do what you need?
my $a = sub { return $_[0] + $_[1]; }; print $a->(3, 5);
Edit: if you really need to do it runtime -- that is, dynamically, how about this:
my $code = 'return $_[0] + $_[1];' my $a = eval "sub { $code }"; print $a->(3, 5);
One thing to consider is that $a is a special variable, used by sort, so you might not want to use that name, but the technique still holds I think.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: eval code generation - parameters & return values
by yoda54 (Monk) on Jun 17, 2012 at 05:00 UTC |