Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > passing an array to another program

Reply
Thread Tools

passing an array to another program

 
 
guser@packetstorm.org
Guest
Posts: n/a
 
      06-23-2006
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

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      06-23-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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';

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      06-23-2006

(E-Mail Removed) wrote:
> 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

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      06-23-2006

Quoth (E-Mail 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

--
Although few may originate a policy, we are all able to judge it.
Pericles of Athens, c.430 B.C.
(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing array of floats (or vectors) into another function - datascope - hmmm. Very ugly... someone C++ 26 10-24-2011 08:17 PM
Passing an array from FORTRAN to C then passing it within C andReturning it to FORTRAN deadpickle C Programming 1 11-07-2010 02:38 PM
passing a string array to another page? agb ASP .Net Web Controls 1 08-28-2003 02:03 PM
passing data between Java program and C program--help pipi Java 1 07-21-2003 05:02 AM
Passing value from one script on one page to another script on another page. Robert Cohen ASP General 3 07-15-2003 01:46 PM



Advertisments