in reply to Re: Are we seeing syntax inconsistency?
in thread Are we seeing syntax inconsistency?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Are we seeing syntax inconsistency?
by sgifford (Prior) on Nov 11, 2005 at 18:22 UTC | |
by Aristotle (Chancellor) on Nov 11, 2005 at 18:29 UTC | |
by sgifford (Prior) on Nov 11, 2005 at 18:56 UTC |