If you eval a string containing a named sub definition, it gets installed into the current package:
c:\test>perl -E"eval 'sub Foo{ return 12345 }'; print Foo();" 12345
If you want to create an anonymous sub and get a reference to it into a variable:
c:\test>perl -E"$f = eval 'sub { return 12345 }'; print $f->();" 12345 c:\test>perl -E"$f = eval 'sub { return "bar" }'; print $f->();" bar
That works also.
In reply to Re: Perl generating embedded Perl
by BrowserUk
in thread Perl generating embedded Perl
by AriSoft
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |