passing an array to another program

Discussion in 'Perl Misc' started by guser@packetstorm.org, Jun 23, 2006.

  1. Guest

    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
    , Jun 23, 2006
    #1
    1. Advertising

  2. 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
    Gunnar Hjalmarsson, Jun 23, 2006
    #2
    1. Advertising

  3. Paul Lalli Guest

    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
    Paul Lalli, Jun 23, 2006
    #3
  4. Ben Morrow Guest

    Quoth :
    > 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.
    Ben Morrow, Jun 23, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pipi
    Replies:
    1
    Views:
    617
    Joseph Millar
    Jul 21, 2003
  2. Rey
    Replies:
    4
    Views:
    10,939
    Roedy Green
    Dec 12, 2003
  3. Replies:
    1
    Views:
    512
    Andrew Thompson
    Oct 31, 2005
  4. deadpickle
    Replies:
    1
    Views:
    981
    Jens Thoms Toerring
    Nov 7, 2010
  5. Robert Cohen
    Replies:
    3
    Views:
    269
    Andrew Durstewitz
    Jul 15, 2003
Loading...

Share This Page