do_code.pl
return sub {print "hello\n"};
do_array.pl
[1 2 3 4 5]
do_hash.pl
{a = 'hello', b = '你好', c = 'bonjour'}
do_excute.pl
#!/usr/bin/perl -w
use strict;
use YAML::XS;
my $code = do 'do_code';
#y $code = eval `cat stat.pl`;
my $ref = ref $code; print "$ref\n";
&$code;
print "\ndo_array\n";
my $array = do 'do_array';
$ref = ref $array; print "$ref\n";
print YAML::XS::Dump $array;
print "\ndo_hash\n";
my $hash = do 'do_hash';
$ref = ref $hash; print "$ref\n";
print YAML::XS::Dump $hash;
执行do_excute.pl的结果
CODE
hello
do_array
ARRAY
---
- 9
- 8
- 7
do_hash
HASH
---
a: hello
b: nihao
c: bonjour