P is for Practical | |
PerlMonks |
Re: How to do that with eval ?by davido (Cardinal) |
on Apr 10, 2004 at 07:40 UTC ( [id://344098]=note: print w/replies, xml ) | Need Help?? |
One problem is that you're ignoring double-quoteish variable interpolation.
Consider the following:
Ok, here's the problem. What you just witnessed is $value being interpolated as a variable into a string, and assigned to $string. Seems harmless. But it can easily get you into trouble.
The problem was that before eval got a chance to see $var, it got interpolated by the double quotes and thus was seen by eval as a literal string rather than a variable. The code that eval saw was:
See the error? You wanted eval to see The situation can be remedied by either using single quotes, or by escaping your double-quoted variables so that eval gets them uninterpolated. It can be tricky deciding which option to use. ...but that's the nature of eval... a little tricky. ;)
Dave
In Section
Seekers of Perl Wisdom
|
|