We don't bite newbies here... much | |
PerlMonks |
Re^2: Are we seeing syntax inconsistency?by Aristotle (Chancellor) |
on Nov 11, 2005 at 17:56 UTC ( [id://507796]=note: print w/replies, xml ) | Need Help?? |
No, that doesn’t work in the general case. It would work here, because the string which eval sees is, say, sub { print 0 } on the first iteration. But if the loop was for( "foo bar", "baz quux" ) ){ ... }, then the eval would incorrectly be called to compile sub { print foo bar }, which may fail to compile or may compile to nonsense. You want to stick the value in a lexical and close over the lexical. That is the correct general solution. Makeshifts last the longest.
In Section
Seekers of Perl Wisdom
|
|