Nice example
Be aware that if you plan to do this with a closure, B::Deparse doesn't pack any variable that the subroutine has closed over. Here is the same example that I posted above using B::Deparse:
use strict; use warnings; use B::Deparse; sub makeGreeting { my $str = "Hello "; return sub { my ($name) = @_; print "$str $name\n"; } } my $greet = makeGreeting(); my $deparse = B::Deparse->new(); print $deparse->coderef2text($greet);
Outputs:
{ use warnings; use strict 'refs'; my($name) = @_; print "$str $name\n"; }
Variable $str appears in the output but its declaration is not "packed" inside the code
citromatik
In reply to Re^2: Turning a reference to a subroutine back into code
by citromatik
in thread Turning a reference to a subroutine back into code
by andreas1234567
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |