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

Take a gander:
#! c:\perl\bin\perl.exe $| = 1; use strict; my ($message,$date,$week,$file); $date = "04/28"; $week = "4"; $message = "\n****** Player Update ******\n"; $message .= `perl z:\\scripts\\baseball\\players.pl`; $message .= "\n****** Stat Download ******\n"; $message .= `perl z:\\scripts\\baseball\\stats1.pl $date`; $message .= "\n****** Weekly Stats Update ******\n"; $message .= `perl z:\\scripts\\baseball\\stats2.pl $week`; $message .= "\n****** Standings Update ******\n"; $message .= `perl z:\\scripts\\baseball\\stats3.pl`; $file = $date."OUTPUT"; if (-f $file) { open(DATA, ">>$file"); } else { open(DATA, ">$file"); } print DATA $file; close(DATA); exit;
Quick explanation:
players.pl updates player information. No problems.
stats1.pl inserts individual player stats from $date. No problems.
stats2.pl updates teams' stats using individual player stats for $week up to $date. Output to file looks good, but the team stats are not updated with the stats inserted from stats1.pl.
stats3.pl updates team standings using team stats. Output looks good, but of course, nothing is updated since the stats didn't change.
All scripts update a local MSSQL7 db via Win32::OLE and work flawlessly from the command line.
Any suggestions?

Replies are listed 'Best First'.
RE: Problems with perl script calling perl scripts
by perlmonkey (Hermit) on Apr 29, 2000 at 10:16 UTC
    Well I dont see anything that looks out of place. So my guess is that there is something wrong with the scripts you are calling. For debugging I would suggest putting the command line strings into another variable, then printing it out, like this:
    $command = "perl z:\\scripts\\baseball\\stats1.pl $date"; print "$command\n"; $message .= `$command`;
    Maybe the command is not actually what you expect. Also you can execute the command that is printed for yourself, just to make absolutely sure it is working as expected.

    Another remote possiblitly is that maybe some environment variables that are needed are not getting set in your script? Maybe use should use the absolute path to your perl executable and not just call 'perl z:...' But I am totally guessing.
      I would put the whole thing in one script and avoid the trouble of getting the scripts to talk to one another. If the script is still unmanageable you can add subroutines and perl modules. You don't show the other scripts, but I am willing to bet they could be small subroutines. My philosophy is to keep it as simple as possible and achieve the objective.
        Just finished doing this. Oddly enuf, I still have the exact same problem. The all-in-one script dies in the same part that the it did when separated.
        When I commented out all the stuff prior to the part where it dies, it ran fine. Arrgh. This should be an interesting weekend.
Re: Problems with perl script calling perl scripts
by chromatic (Archbishop) on Apr 30, 2000 at 06:10 UTC
    Hmm, try something like this: print DATA $message; (Assuming that wasn't a typo, that is.)

    You can check the special variable $? to see if your backticks call executed successfully (it will be 0 if it works). Since variables are interpolated in that context, the only other thing is that the Perl executable isn't in the path of the subprocess.

      Yea, that was a typo.
      At any rate, I've tried the two viable solutions offered, putting the command into a variable and printing it out as well as checking the status of the backtick call.
      Oddly enough, both were correct as in the expected command call was printed out and the return status was successful.
      Well, I guess I'll just have to throw them all into one script. If I ever come across the problem I'll be sure to let everyone know.
Re: Problems with perl script calling perl scripts
by Anonymous Monk on Apr 29, 2000 at 04:38 UTC
    I think that instead of creating a new process to call this child perl script, I would read the script as a text file and simply use the function eval()!
RE: Problems with perl script calling perl scripts
by mr_ayo (Beadle) on May 24, 2000 at 21:59 UTC
    Update: Working now. stats2.pl was accessing an external file which I apparently don't have access to from the "at" environment. For now I've put the necessary info from the file into the script to get it working.