use strict; use warnings;
my $do_me="do_me.pl";
foreach my $ending ('',"\n") {
print "Create file with",($ending?'':'out')," newline\n";
open(OUT,'>',$do_me) or die "$!";
print OUT "q(string)$ending";
close OUT;
$!=0;
my $result=do $do_me;
print "Can not read $do_me: $!\n" if $!;
print "Can not evaluate $do_me: $@\n" if $@;
print("$result\n") if defined $result;
}
####
If "do" cannot read the file, it returns undef and sets $! to
the error. If "do" can read the file but cannot compile it, it
returns undef and sets an error message in $@. If the file is
successfully compiled, "do" returns the value of the last
expression evaluated.
####
use strict; use warnings;
my $do_me="do_me.pl";
foreach my $ending ('',"\n") {
print "Create file with",($ending?'':'out')," newline\n";
open(OUT,'>',$do_me) or die "$!";
print OUT "undef$ending";
close OUT;
$!=0;
my $result=do $do_me;
print "Can not read $do_me: $!\n" if $!;
print "Can not evaluate $do_me: $@\n" if $@;
print("$result\n") if defined $result;
}