To answer your question title:
Will code after eval(die “some error message”) continue to be executed?
The answer is "No". But please read on, because this is not a problem, but a misunderstanding about the Perl syntax involved.
The line:
my $eval_rtn = eval( opendir(BASEDIR,$baseDir) or die "dir doesn't exist!\n" );
Does not get as far as running the eval
. The syntax you have used with (..)
brackets takes a scalar value, and before the eval
does anything at all, it is waiting for the opendir...or die
expression to return a string (which will then be evaluated). To make it equivalent to your other example, you could make the param a string:
my $eval_rtn = eval( q{opendir(BASEDIR,$baseDir) or die "dir doesn't exist!\n"} );
You could also use the block form instead:
my $eval_rtn = eval { opendir(BASEDIR,$baseDir) or die "dir doesn't exist!\n"; };
I would recommend using the block form where possible, it is usually easier to debug, and in your case better matches the exception handling semantics that you want to achieve.