http://qs321.pair.com?node_id=536380

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:

my $fee="FEE" my $fi="FI" my $fo="FO" my @fum=qw / fee fi fo fum /
and I have a very simple Perl script as such:
use Data::Dumper; use warnings; open(DAT,"< datafile.txt") or die $!; while (my $line=<DAT>){ chomp $line; eval $line; if ($@){ print $@; } } print Dumper($main::fee,$fi,$fo,@fum);

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:

perl loadData.pl Name "main::fum" used only once: possible typo at loadData.pl line 15. Name "main::fo" used only once: possible typo at loadData.pl line 15. Name "main::fi" used only once: possible typo at loadData.pl line 15. Name "main::fee" used only once: possible typo at loadData.pl line 15. $VAR1 = undef; $VAR2 = undef; $VAR3 = undef;
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:

[pberghol@cowdawg ext-files]$ perl loadData.pl Global symbol "$fi" requires explicit package name at loadData.pl line + 16. Global symbol "$fo" requires explicit package name at loadData.pl line + 16. Global symbol "@fum" requires explicit package name at loadData.pl lin +e 16. Execution of loadData.pl aborted due to compilation errors.
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:
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 = undef; $VAR2 = undef; $VAR3 = undef;

What in the world is going on here?