do is, essentially, a file-slup + eval all in one. Try the following:
data.txt
--------
$foo = "Hello, World";
data.pl
-------
#!/usr/local/bin/perl
use 5.6.0;
use strict;
our $foo;
do 'data.txt';
print $foo, $/;
__END__
Note that this will only work with non-lexical variables. If you change to my $foo;, this will not work, due to the lexical scoping of my. Before 5.6.0, this trick is accomplished with use vars qw/$foo/; instead of our $foo;
------ We are the carpenters and bricklayers of the Information Age. Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement. |