Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sending array and scalar variable as param in System function

Status
Not open for further replies.

globalvasu

Programmer
Oct 31, 2003
4
US
How do i call another perl program using system function and pass scalar variable and array as parameters
how do i read the same in the called script.

Ex :

my $x="test";
my @arr=(10,20,30);
system ('test.pl',$x,@arr);
 
You do it mostly like you have done. To capture the output of the script, you need to use backticks instead of the system command to launch the program. @arr wont work like you think because it is being used in scalar context. The only value that will be returned is number of items stored in the array - not each value.

Your script should look something like this:

my $x="test";
my @arr=(10,20,30);
$result = `'test.pl',$x,$arr[0],$arr[1],$arr[2]`;

Notice that the backticks are the ` ` characters instead of ' '. Backticks can be found on the same key as tilde (~).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top