in reply to Reading Variables from a File
Which will run config.pl at run time assuming a nice handy slurp function is provided to read a file...use strict; my $cake = 'chocolate'; my $pie = 'apple'; eval slurp("config.pl");
So when config.pl contains...## slurp - read a file into a scalar or list sub slurp { my $file = shift; local *F; open F, "< $file" or die "Error opening '$file' for read: $!"; if(not wantarray){ local $/ = undef; my $string = <F>; close F; return $string; } local $/ = ""; my @a = <F>; close F; return @a; }
...the pie and cake get set to your favourites rather than the defaults.$pie = 'pecan'; cake = 'fairy';
If you are interested in errors from the eval, it can be followed by something like...
if($@){ print "Some errors happened...\n\n"; print $@."\n\n"; print "Oh well...\n"; }
|
|---|