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

Hi monks I have a question that suppose i have got two perl scripts test1.pl and test2.pl and my test2.pl is a script which requires standard input from keyboard and depending upon the i/p it gives the o/p.Now what i want to know is that can i write a script test1.pl from which i can call test1.pl
  • Comment on executing a perl scripts within another perl script

Replies are listed 'Best First'.
Re: executing a perl scripts within another perl script
by davidrw (Prior) on Aug 29, 2005 at 11:56 UTC
    Take a look at perldoc -f do to start. You may however, want to consider refactoring a little -- also look at perldoc -f require and perldoc perlmod for other methods.
Re: executing a perl scripts within another perl script
by izut (Chaplain) on Aug 29, 2005 at 12:07 UTC
    You are going through the wrong way if you are thinking about calling one script from another. You probably need to read perldoc perlmodlib to learn how you write your own module - the right thing for make components and reuse code you wrote.


    Igor S. Lopes - izut
    surrender to perl. your code, your rules.
Re: executing a perl scripts within another perl script
by Tanktalus (Canon) on Aug 29, 2005 at 14:40 UTC

    Check out IPC::Open2 or IPC::Open3. Both of these are standard parts of the perl distribution. You can send info to the test2's stdin, and receive info back from test2's stdout.

Re: executing a perl scripts within another perl script
by josera (Beadle) on Aug 29, 2005 at 15:13 UTC
    Hi:
    Have you try the command "system"? It's very simple and it works to call an external program and to execute. You can read more about it in the documentation.
    I hope that could help you.
    Yours sincerely
    José Ramón
Re: executing a perl scripts within another perl script
by punkish (Priest) on Aug 29, 2005 at 14:12 UTC
    why on earth would you want to do that? A script is a program... just include the logic of test2.pl within test1.pl and you are done. Of course, if you need to have the logic be reusable, then put that logic in a package, and use Yourpackage within test1.pl. Either way, you need only one script.

    Perhaps, if you gave us the contents (or, at least the logic of) what you are trying to do, we could provide more suggestions.

    --

    when small people start casting long shadows, it is time to go to bed