good chemistry is complicated,
and a little bit messy -LW
eval not behaving like I expected... why?by blue_cowdawg (Monsignor)
|on Mar 13, 2006 at 21:11 UTC||Need Help??|
blue_cowdawg has asked for the
wisdom of the Perl Monks concerning the following question:
Drawing inspiration from a couple of different sources I decided to try something and it doesn't work quite like I expected it to.
Heres the deal. I have a data file as such:
and I have a very simple Perl script as such:
That's not the code I started off with, it is pretty much what it morphed into as I tried to make this thing work. What I was expecting to have happen was the variables $fee,$fi,$fo and @fum to be defined as a result of reading in the data file and feeding each line through eval. Reading the perldoc eval and looking at the man page for Inline::Files of all things led me to believe this should work. Part of my inspiration was to come up with a clever answer to this question and so far I've failed to using this method. And indeed a strange thing happened on the way to enlightenment.
New before you yell at me, I know I don't have use strict; in there. That was by choice as part of my intellectual excersize. When the code runs I see the following:
In one set of lines I'm being told the the variables are only being used once during the scope and the other set are telling me the variables are not being set at all! Huh?
So, I turn on strict to dig at this further and I see:
OK.. I'm seeing compile time errors... that makes sense.. sorta... Let's dig ourselves deeper and set the package names for all those variables. I'm back to the same complaints again:
What in the world is going on here?