in reply to eval not behaving like I expected... why?

You're declaring your variables with my, so as soon as you leave the eval block they go out of scope.

I just tested it to be sure, and if you just remove the "my" from each line in the datafile, things will behave as you expect. Of course under strict you'd still get the "Global symbol ... requires explicit package name at ./rf line ..." errors unless you declare them somewhere.

Replies are listed 'Best First'.
Re^2: eval not behaving like I expected... why?
by blue_cowdawg (Monsignor) on Mar 13, 2006 at 21:27 UTC
        You're declaring your variables with my, so as soon as you leave the eval block they go out of scope.

    Good thought... taking the "my" out now gives the following spew:

    $ perl loadData.pl Name "main::fum" used only once: possible typo at loadData.pl line 16. Name "main::fo" used only once: possible typo at loadData.pl line 16. Name "main::fi" used only once: possible typo at loadData.pl line 16. Name "main::fee" used only once: possible typo at loadData.pl line 16. Variable "$fee" is not imported at (eval 1) line 1, <DAT> line 1. Global symbol "$fee" requires explicit package name at (eval 1) line 1 +, <DAT> line 1. Variable "$fi" is not imported at (eval 2) line 1, <DAT> line 2. Global symbol "$fi" requires explicit package name at (eval 2) line 1, + <DAT> line 2. Variable "$fo" is not imported at (eval 3) line 1, <DAT> line 3. Global symbol "$fo" requires explicit package name at (eval 3) line 1, + <DAT> line 3. Variable "@fum" is not imported at (eval 4) line 1, <DAT> line 4. Global symbol "@fum" requires explicit package name at (eval 4) line 1 +, <DAT> line 4. $VAR1 = undef; $VAR2 = undef; $VAR3 = undef;
    Following that thought one step further, let's declare them as "our." Run the code and we still see spew, but not as severe:
    $ perl loadData.pl Name "main::fum" used only once: possible typo at loadData.pl line 16. Name "main::fo" used only once: possible typo at loadData.pl line 16. Name "main::fi" used only once: possible typo at loadData.pl line 16. Name "main::fee" used only once: possible typo at loadData.pl line 16. $VAR1 = 'FEE'; $VAR2 = 'FI'; $VAR3 = 'FO'; $VAR4 = 'fee'; $VAR5 = 'fi'; $VAR6 = 'fo'; $VAR7 = 'fum';

    I guess in the end that means that you have to pre-declare the variables before reading in the "configuration file" and getting the values defined. Not pretty... but it works. I like the way I normally do it better. Which is to sey I either create a module and export my values or I use something like XML::Simple to do the dirty work.