Nesh has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perl Monks I have many perl programs that have been scheduled to run one after the other through batch files. Now as I want to log every thing that goes on during processing of these jobs I am trying to write a perl program where the perl programs will be called in certain order. But I am not able to get the output as required even while working on example. like I have this program
use strict; use warnings; my $sec; my $min; my $hour; ($sec, $min, $hour) = localtime();

I am trying to call it from another perl program

#!usr/bin/Perl use strict; use warnings; my $results=`perl stime.pl`; print $results;

It does not show me the output. Please guide me where I am going wrong.

20050215 Janitored by Corion: Added code tags

Replies are listed 'Best First'.
Re: Calling many perl scripts from one master perl script
by Tanktalus (Canon) on Feb 14, 2005 at 23:33 UTC

    First off, from what I can tell, your first program doesn't have any output. (Hard to tell without code tags.)

    Second, even any output it did have should be captured by the back-ticks. Thus, you wouldn't "see" the output - it would be stored in $results. Which is probably what you want, but I can't quite be sure. Ideally, you'd explain what you expect from this, and then we could talk about why it isn't doing what you expect, and what it would take to get where you want to go. (Computers are funny - they do exactly what you tell them, even if that's not what you meant ;->)

    Third, and this is pretty minor, your perl is probably not called "usr/bin/Perl" - it's probably "/usr/bin/perl" (note the leading slash, and lower-case perl).

    Finally, my last minor nit, and here we're scraping the barrel: stime.pl should have the hash-bang line in it, or you should use $^X to call perl for stime.pl. The former allows stime.pl to control which interpreter to use (I have two different perls on my system), the latter allows your controller's hash-bang line to control the interpreter. The current code puts the onus on the backtick line to figure out the perl, which makes it harder to change later, and you may be surprised what you get. The stime.pl may expect one thing, and controller.pl or whatever may expect something else, and they may both be wrong... (I would go for a hash-bang line in stime.pl and get rid of the "perl" in the $results line.)

      Thanks a lot for the prompt reply. Here suppose say that the first file has one more line then it will print the current time (eg 16:4:50) on the screen when ran. But I want the same thing to be printed by the second program when it calls the first program and stores it in $results. I am very new to perl so all the mistakes. Thanks for correcting all those.
        I don't see any problem with it at this point. Prints out correctly for me, unless I'm missing something throught the lack of code tags. What's a code tag, you say? Simple. It's an html tag that says <code > (without the trailing space). Surround your blocks of code in code tags (Writeup Formatting Tips) so that the output looks like:
        #!/usr/bin/perl use strict; use warnings; my $results = `perl stime.pl`; print $results;
        Cheers, LassiLantar
Re: Calling many perl scripts from one master perl script
by cognizant (Pilgrim) on Feb 16, 2005 at 07:35 UTC
    Try this.
    #fir.pl print "hi how r u"; #sec.pl system("perl fir.pl");

    cheers --c