in reply to Re: Re: IO::Select - is it right for this?
in thread IO::Select - is it right for this?

This is good, but not quite right. The array @out is working nicely.
It seems that when I try to adapt this to my needs, I only get results from one of my search engines.

I tried eliminating one of the exit; statements, but it doesn't quite work right. Eliminating the first one doesn't change anything. Eliminating the second does give me all the outputs, but give me a lot of additional garbage with it, and messes up the output. Here is the code as it stands now.

my @out; my $first_child; $|=1; my $pid= open($first_child, '-|'); if ($pid) { # parent @out= <$first_child>; } else { my(@child, @childpid); for (my $i=0; $i<$children; ++$i) { $childpid[$i]= open($child[$i], '|-'); if ($childpid[$i]) { # do nothing yet } else { $call = <Something I make here>; # sorry, can't show that open (OUT, "| $call"); close (OUT); exit; } } foreach (@child) { close $_; } exit; }

$call is a PERL call that is generated by using information gathered elsewhere in the program. It is built just prior to the call to run it, and will be different for each iteration of the for loop.
Then I work with @out in the rest of the code. I'm thinking that the issue is with how I run $call, but I'm not sure how else to do this.

IPC is new to my coding bag of tricks, so I appreciate all the input everyone has given.

Replies are listed 'Best First'.
Re: Re: Re: Re: IO::Select - is it right for this?
by mcogan1966 (Monk) on Oct 22, 2003 at 12:54 UTC
    Doh!
    Forget that last post.
    I put the foreach(@child) loop in the wrong place. My bad. Sorry. :)
Re: Re: Re: Re: IO::Select - is it right for this?
by Skeeve (Parson) on Oct 23, 2003 at 06:51 UTC
    This part:
    else { $call = <Something I make here>; # sorry, can't show that open (OUT, "| $call"); close (OUT); exit; }
    can be simplified to
    else { $call = <Something I make here>; # sorry, can't show that exec $call || die "Something went wrong!"; }
    But you should better consider using @call, putting each option and parameter of the call into it's own @call element and using the complete path for the first parameter, the program's name.
    For example instead of
    $call= "myperlscript -param1 $var1 -param2 $var2"; exec $call;
    use something like this:
    @call= ('/my/home/dir/myperlscript','-param1',$var1,'-param2',$var2); exec @call;