Well, func4 is a closure. Perl sees that it uses a lexical variable from its declaration scope, so it keeps a link to that scalar value for the function to still be able to access it (and to prevent the scalar from being deleted at the end of the file). func3 holds no such link. Now I don't know what variable func3 acccesses, because the eval doesn't fail, but calling eval "$_[0]++" always returns 0 so it's not always the same var.
Instead of exporting a package variable I intended to return the value via 'eval' in a module function.Honestly that sounds like a bad idea. Maybe you can use a hash instead.
In reply to Re: eval in perl package
by Eily
in thread [SOLVED]: eval in perl package
by MarcusE
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |