[Boston.pm] return value of string eval()?

"Greg London" <email-2Ro/Dj86MvDSUeElwK9/[email protected]> Thu, 25 Apr 2019 12:18:40 -0400
Newsgroups gmane.comp.lang.perl.perl-mongers.boston
Message-ID <[email protected]>

I thought the return value of eval(<my string of perl code>) was
defined if eval'ed oK
undef if failed to eval OK.

I have some code that runs without any issue when directly executed.
But errors out when I have it as part of a string eval().

My script is doing that eval( my string ) version
and is bombing out because the return value is not defined.

Far as I can tell the code should compile and execute fine.

Am I misunderstanding teh return value of eval()?
Greg


#########################################################333

print "directly executing code:\n";

	my @fruits = (
		#"apple",
		#"banana",
		#"cherry",
		#"dates",
	);



	foreach my $fruit ( @fruits ){

		print "fruit is '$fruit'\n";
	}
print "end of direcct execution\n";

print "Executing same code as a string eval() block\n";

my $code = <<'BLOCK';


	my @fruits = (
		#"apple",
		#"banana",
		#"cherry",
		#"dates",
	);



	foreach my $fruit ( @fruits ){

		print "fruit is '$fruit'\n";
	}

BLOCK
	unless(defined(eval($code))){
		print "ERROR: failed to eval code block\n";
		print "BECAUSE $@";

	}


print "\n\nend of string eval() execution\n";

##################################################