in reply to how to execute multiple Perl scripts

Hello vasuperl and welcome to the Monastery!

Since you are very new to Perl, you could get started and gain confidence by writing four small standalone test scripts (step1.pl, step2.pl, step3.pl, step4.pl) like so:

# step1.pl print "This is step1.\n"; exit 0; # step2.pl print "This is step2.\n"; exit 0; # step3.pl print "This is step3.\n"; exit 42; # step4.pl print "This is step4.\n"; exit 0;
We deliberately make these test scripts as simple as possible to make it easier to test. Note that we use the Perl exit function to explicitly set the script exit code. We use the standard convention that an exit code of zero indicates success, while non-zero indicates failure. We will test this exit code in our "runner" script to determine if any of the steps failed.

With that preliminary step done, you can then edit these scripts in different ways to test different scenarios, and so confirm that your "runner" script works in all scenarios. For example, changing step3.pl above from exit 42 to exit 0 tests the case of all scripts successful.

With that done, write runner.pl to run these four scripts as per your spec. For example:

# runner.pl use strict; use warnings; $| = 1; my @scripts = ('step1.pl', 'step2.pl', 'step3.pl', 'step4.pl'); for my $scr (@scripts) { my $cmd = "$^X $scr"; print "Run '$cmd'..."; my $out = qx{$cmd}; my $rc = $? >> 8; print "rc=$rc\n"; print "Output:$out\n"; if ($rc != 0) { print "Main script $0 exit $rc\n"; exit $rc; } } print "All commands finished successfully.\n";
Setting the $| = 1 perl special variable ensures that stdout is auto-flushed; this is commonly used in scripts that run external commands to make it clearer whether the stdout is coming from the runner script itself or the external command. The $^X special variable contains the name of the currently running perl, while $? is used to extract the exit code of the last command run, and $0 is the name of the current script (runner.pl in this case). To learn more about Perl special variables, see perlvar.

The qx operator is used to run a command and capture its stdout. If you don't want to capture the command's output, simply use the system function instead.

Please note that the example runner.pl above is just one way to do it, so as to get you started. Perl offers a wide variety of ways to run external commands depending on your needs. To learn more, see system, qx, exec and open -- or a Perl tutorial on the subject, for example perlhowto or How to run a shell script from a Perl program? (Perl Monks categorized answer).

The advantage of starting with a small self-contained test script, as shown above, is that you can experiment with different ways to run an external command, and so improve your Perl.