call perl script through another perl script with arguments
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
call perl script through another perl script with arguments
Hi All,
I'm trying to call a perl script with arguments, through another perl script, but its not taking the argumements. if i'm excutating the same script outside with argumetns its working fine,
the Main script looks like this
</
use warnings;
require "addition.pl";
my $n=system("perl addition.pl -12.3 3.2");
print "Sum is $n"
/>
When i call addition.pl separately out side, with same arguments it gives result.
</
perl addition.pl -12.3 3.2
Sum is -9.1
/>
thanks in advance
I'm trying to call a perl script with arguments, through another perl script, but its not taking the argumements.
You really want
Code:
</
use warnings;
require "addition.pl";
# Use qx to capture output of shell command.
# "system" requires an array and only returns the exit code.
my $n = qx("/path/to/perl addition.pl -12.3 3.2");
print "Sum is $n"
/>
</
use warnings;
require "addition.pl";
# Use qx to capture output of shell command.
# "system" requires an array and only returns the exit code.
my $n = qx("/path/to/perl addition.pl -12.3 3.2");
print "Sum is $n"
/>
Hi I tried using "qx" still it doesn't show up any result
The full code is as given below
add.pl
Code:
my $sum= qx("addition.pl 10 -20");
print "Result is $sum"
As PMP pointed out, the double quotes in my example were incorrect.
Quote:
Originally Posted by David1357
You really want
Code:
</
use warnings;
require "addition.pl";
# Use qx to capture output of shell command.
# "system" requires an array and only returns the exit code.
my $n = qx(/path/to/perl addition.pl -12.3 3.2); # No double quotes needed
print "Sum is $n"; # Semi-colon is needed
/>
use warnings;
require "addition.pl"
my $sum= qx(perl addition.pl 10 -20);
print "Result is $sum";
i've removed the quotes, Still the same error
syntax error at add.pl line 4, near "my "....
Please help its been 2 days, i'm struggling with this error
i've added "use strict " at the top of the code, now it has given bit more explanative error lines
syntax error at add.pl line 5, near "my "
Global symbol "$sum" requires explicit package name at add.pl line 5.
Global symbol "$sum" requires explicit package name at add.pl line 6.
Execution of add.pl aborted due to compilation errors.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.