in reply to how to create makefile?

Your question is not really a Perl question and more a question of job control or a shell question. Personally, I would use a plain shell script instead of a makefile, as you have not explained how the two processes depend on each other and by what mechanism make would determine that it only needs to run the second step.

#!/bin/ksh set -e perl -I -Mmod1 -Mmod2 pgm.pl paramFile perl -I -Mmod3 -Mmod4 pgm2.pl paramFile2

The -e switch makes the shell script stop if any of the programs fails.

Replies are listed 'Best First'.
Re^2: how to create makefile?
by carolw (Sexton) on Jan 09, 2015 at 09:09 UTC

    Perhaps, I have mixed up the c makefile with perl makefile. as we put all c programs in the make file, we compile and then, we run, I thought that I can run automatically the perl programs in the same manner.

    Regarding the dependency, the first script has to be finished without error as it generates files for the 2nd script. beyond that there is no other dependency.

    I should perhaps have said that all modules, mod1, ..., mod4 and pgm1 and pgm2 are in the same directory. If they are not, I think for the modules, the path should be given after -I.

      This sounds like a great job for make, but this is Perlmonks, not makemonks. I suggest that you learn about make and then use that knowledge to create the appropriate Makefile. If you want to implement this in Perl, there is Algorithm::Depends, which allows you to list file dependencies and then perform actions based on the dependencies.

      The Makefile for your case would likely be something like the following. You will need to preserve the tabs, because tabs are special characters in make:

      .PHONY all all: resultfile1 resultfile2 resultfile1: perl -I -Mmod1 -Mmod2 pgm.pl paramFile resultfile2: resultfile1 perl -I -Mmod3 -Mmod4 pgm2.pl paramFile2

      As you haven't told us the names of the resulting files of the program runs, I've substituted resultfile1 and resultfile2 for them.

        so, do I not have to use

        use ExtUtils::MakeMaker; WriteMakefile( NAME => 'myPgm', VERSION => .... );

        with your code for the make or they are 2 different things? If different, how to run yours, just by typing make or perl fileName.PL?