From: Robert Thompson <[EMAIL PROTECTED]> > I am using Data:Dumper in a script and am running into a problem with > "use strict" and eval. Basically the conundrum is that the data I > will be loading from the Data::Dumper file is going to be based off > input to the final script, so it may not be the > same for each run of the script. There will be many dumper files that > have different variables. I cannot predeclare them for "use strict" > since I won't know what they are until the eval. > > The only work around is to turn off use strict, but I would like to > continue using it. Is there a way, either with Data:Dumper, or > something else to get this to work?
You can turn strict off for a block of code and keep it on elsewhere : use strict; .... { no strict; eval shift(@wholetemplatefile); # define $datadumperfile. eval shift(@wholetemplatefile); # define $outfile. } # and now the strict is turned on again. > Here is the snippet of code and some source files, so if one is > confused hopefully this will explain: > > eval shift(@wholetemplatefile); # define $datadumperfile. eval > shift(@wholetemplatefile); # define $outfile. > shift(@wholetemplatefile); # Get rid of the divider. > > # Get the Data::Dumper information. > open (READ_DD, $datadumperfile); > while(<READ_DD>) { > eval $_; Well ... it would be better to read the whole file into a scalar and eval it at once. Your code will fail if any of the variables contained a newline. I'd use : open (READ_DD, $datadumperfile); { local $/; # this forces the <HANDLE> to read the whole file # not just one line. See perldoc perlvar my $data = <READ_DD>; eval $data; } close READ_DD; > } > close(READ_DD); > > > The error message and source files: > > Global symbol "$Test01" requires explicit package name at (eval 3) > line 1, <READ_DD> chunk 1. $Test01? And you might have $Test02, $Test03 and so on? You don't do this ${"Test$i"} = "hello world"; do you? Please consider using arrays or hashes, instead of a group of variables. Also please read this : http://www.plover.com/~mjd/perl/varvarname.html Jenda =========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ========== There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain. I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]