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

Greetz! I am developing a suite of scripts that read a MysQL database that is maintained using DBI/DBD. One script runs on a regular basis as a daemon and interrogates the database. When it finds a specific pattern match, it is supposed to run another script based on that data. So, what would be your recommendations be for running a script from within a script? The criterion is that once the callee script has been initiated by the caller, it will run standalone and won't need to return to the caller. If you see what I mean :-)

Mildew Hall.. Home of PurePostPro and other Perl goodies! Not only oysters create Pe[a]rls

  • Comment on running a Perl script from a Perl script

Replies are listed 'Best First'.
Re: running a Perl script from a Perl script
by rdfield (Priest) on Feb 12, 2002 at 10:46 UTC
    If you read perlfunc regarding system and exec you may find what you need.

    rdfield

Re: running a Perl script from a Perl script
by peterg22 (Novice) on Feb 12, 2002 at 14:16 UTC
    OK .. I did RTFM in the end.. and after due deliberation came up with:

    my $programtorun = 'spawnee'; my $parameters = 'a b c flapjack sweets monkeybusiness'; my @cmdline = ( $programtorun, $parameters ); system ( @cmdline );

    .. which runs spawnee

    if ( @ARGV ) { foreach ( split(' ', $ARGV[0] ) ) { print "Parameter is $_\n"; } }

    Do i get my 1 point back now. please .. sir ?

    Mildew Hall.. Home of PurePostPro and other Perl goodies!
    Not only oysters create Pe[a]rls

Re: running a Perl script from a Perl script
by philou (Beadle) on Feb 12, 2002 at 13:38 UTC
    You could do something like:

    First script:
    #!/usr/bin/perl -w .... { local @ARGV = qw( one two three ); require "second_script.pl"; exit(); }