Is it possible to execute Perl script within another script?
Hello friends,
I don't have any Idea with PERL programming. Actually I use to work with perl program execution so my question is may be simple but I am not good at writing the code. What I want to ask is it possible to call a perl script from within another script? I want to call a perl script into another please let me know if it is possible? Is it possible to execute it?
Thanks in advance.
Re: Is it possible to execute Perl script within another script?
If you would like to make a call to, or reference, a Perl script from within a different Perl script, you can accomplish this a system(), exec() or the backtick operator to the path for Perl. For example:
Code:
system("/usr/bin/perl /path/to/my_script.pl ");
Or store output to array:
Code:
@myarray = `/usr/bin/perl mysecondperlscript.pl`;
source: http://theos.in/perl/how-can-i-call-...-from-another/
Re: Is it possible to execute Perl script within another script?
Try this:
add.pl
Code:
my $sum = qx(perl addition.pl 10 -20); ## Remove double quotes from your code
print "Result is $sum";
addition.pl
Code:
$x, $y) = @ARGV;
if ( !defined($x) ) {
print STDERR"usage add <x> <y>\n";
exit;
}
else
{
$n = 0;
$n = $x + $y;
}
print $n;