passing an array to another program

G

guser

I have a scheduler program that hands off tasks to a tasking program
like this

my $retval = `tasker.pl @tasks`;

where the tasks are built like this

push (@tasks,"/program.pl --var=$val");

the tasker program gets the data but ARGV breaks up the task strings
into pieces
(@ARGV)
/program.pl [0]
--var=var1 [1]
/program.pl [2]
--var=var2 [3]

Where I need the data to be recieved like I passed it
(@ARGV)
/program.pl --var=var1 [0]
/program.pl --var=var2 [1]

Is there a way to force sending a series of strings (with spaces in in
the string) in array format to another program so that the destination
program can recieve each string intact without being split when
accessing ARGV?

thanks
 
G

Gunnar Hjalmarsson

I have a scheduler program that hands off tasks to a tasking program
like this

my $retval = `tasker.pl @tasks`;

where the tasks are built like this

push (@tasks,"/program.pl --var=$val");

the tasker program gets the data but ARGV breaks up the task strings
into pieces
(@ARGV)
/program.pl [0]
--var=var1 [1]
/program.pl [2]
--var=var2 [3]

Where I need the data to be recieved like I passed it
(@ARGV)
/program.pl --var=var1 [0]
/program.pl --var=var2 [1]

Is there a way to force sending a series of strings (with spaces in in
the string) in array format to another program so that the destination
program can recieve each string intact without being split when
accessing ARGV?

If tasker.pl is a Perl program:

@ARGV = @tasks;
my $retval = do 'tasker.pl';
 
P

Paul Lalli

I have a scheduler program that hands off tasks to a tasking program
like this

my $retval = `tasker.pl @tasks`;

where the tasks are built like this

push (@tasks,"/program.pl --var=$val");

the tasker program gets the data but ARGV breaks up the task strings
into pieces
(@ARGV)
/program.pl [0]
--var=var1 [1]
/program.pl [2]
--var=var2 [3]

Where I need the data to be recieved like I passed it
(@ARGV)
/program.pl --var=var1 [0]
/program.pl --var=var2 [1]

Is there a way to force sending a series of strings (with spaces in in
the string) in array format to another program so that the destination
program can recieve each string intact without being split when
accessing ARGV?

The exact same way you would do it if you were not using perl, but
using the shell directly: enclose each entire argument in single
quotes:

push (@tasks,qq{'/program.pl --var=$val'});

Note that you could keep the "" rather than qq{}, but I prefer not to
use " and ' right next to each other in any piece of code.

Paul Lalli
 
B

Ben Morrow

Quoth (e-mail address removed):
I have a scheduler program that hands off tasks to a tasking program
like this

my $retval = `tasker.pl @tasks`;

where the tasks are built like this

push (@tasks,"/program.pl --var=$val");

the tasker program gets the data but ARGV breaks up the task strings
into pieces
(@ARGV)
/program.pl [0]
--var=var1 [1]
/program.pl [2]
--var=var2 [3]

Where I need the data to be recieved like I passed it
(@ARGV)
/program.pl --var=var1 [0]
/program.pl --var=var2 [1]

Is there a way to force sending a series of strings (with spaces in in
the string) in array format to another program so that the destination
program can recieve each string intact without being split when
accessing ARGV?

Do
open my $PIPE, '-|', 'program.pl', @tasks;
and then read all of the pipe.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top