I am confused about how "die" works. Here is an example of the source of
my confusion.

I have two files (Perl scripts) in the same directory. They are named
"test1.pl" and "test2.pl". They are shown below.

When test1 is executed, it fires the "shot" in test2. The warning "OK,
Hombre, die!" is followed by "You missed!" The "die" line in "shot" has
no effect.

When test2 is executed, it fires the same "shot". But now "OK, Hombre,
die!" is followed by the error output "I'll die, but only under
protest!" The "die" line in "shot" is now working.

So this is my question. Why is the "die" line in the test2 "shot"
invisible when test1 is in control?

Thanks in advance for your input.

- Vic

P.S. You can throw away the "use FindBin" line in test1 and replace
"$Bin" in the "do" line with the test2's directory.

=== test1.pl ===
#!/usr/bin/perl -w

use FindBin qw($Bin);

do "$Bin/test2.pl";
print "You missed!\n";

=== end test1.pl ===


=== test2.pl === #!/usr/bin/perl -w

shot();

print "You missed!\n";

sub shot {
        print "OK, Hombre, die!\n";
        die "I'll die, but only under protest!";
}

=== end test2.pl ===



Reply via email to