use strict;
my $num = shift;
if ($num) {
if ($num % 2) {
print "$num is calling system...\n";
system("perl test.pl " . ($num - 1));
print "$num is finished calling system.\n";
} else {
print "$num is calling exec...\n";
exec("perl test.pl " . ($num - 1));
print "$num finished calling exec.\n";
}
}
####
$ perl test.pl 5
5 is calling system...
4 is calling exec...
3 is calling system...
2 is calling exec...
1 is calling system...
1 finished calling system.
3 finished calling system.
5 finished calling system.
####
D:\PerlCode>perl test.pl 5
5 is calling system...
4 is calling exec...
5 is finished calling system.
3 is calling system...
D:\PerlCode>2 is calling exec...
3 is finished calling system.
1 is calling system...
1 is finished calling system.