TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   Need Perl script to execute from another. (http://forums.techarena.in/software-development/1200614.htm)

beelow 20-06-2009 09:02 AM

Need Perl script to execute from another.
 
Hi,

I am new with PERL programming.
I have a question. Is it possible to call a Perl script from an another script. The problem is how to get a response from the script?

Any help will be appreciated.

Rafiq 20-06-2009 09:12 AM

Re: Need Perl script to execute from another.
 
This will call a new perl process, and may be more expensive on the
Code:

system. On the other hand I can do
Code:

But How do I get the response of the script.
Probably the dimpliest way is to make called script a module and run it
using either 'use' or 'require'.
If you care about speed, consider using do 'filename.pl', which will avoid firing up a new Perl interpreter.

Raffaele 20-06-2009 09:17 AM

Re: Need Perl script to execute from another.
 
I think you can do the following;
1. backticks: $retVal = `perl somePerlScript.pl `;
2. system() call
3. eval
The eval can be accomplished by slurping the other file into a string (or a list of strings), then 'eval'ing the strings
Code:

#!/usr/bin/perl
open PERLFILE, "<somePerlScript.pl";
undef $/;  # this allows me to slurp the file, ignoring newlines
my $program = <PERLFILE>;
eval $program;

4. do:
Code:

do 'somePerlScript.pl'
For more discussion.


All times are GMT +5.5. The time now is 05:52 PM.