in reply to Re^3: Multiple asynchronous execution of commands
in thread Multiple asynchronous execution of commands

That worked nicely. Code snippet:
my $mysql = q{/usr/local/mysql/bin/mysql --host= [...]}; my @fh; my $i = 0; for my $sql ( q{SELECT id INTO OUTFILE \'/sort/clh/na\' FROM addr}, q{SELECT id INTO OUTFILE \'/sort/clh/ne\' FROM email}, q{SELECT id INTO OUTFILE \'/sort/clh/np\' FROM phone} ) { my $cmd = "echo $sql | $mysql"; open( $fh[$i++], '-|', $cmd ) or die "Failed opening $sql: $!\n"; } say "All spawned - waiting"; for my $i (0..$#fh) { while (defined (my $line = readline( $fh[ $i ] ))) { print "FH$i: $line"; } }
And as you pointed out, I could use IO::Select if I cared about knowing when each command finished.

Replies are listed 'Best First'.
Re^5: Multiple asynchronous execution of commands
by BrowserUk (Patriarch) on Jan 23, 2016 at 01:35 UTC
    # work around parsing problem with <$fh$i> below

    You can avoid the unnecessary assignment by using readline, the function that underlies that version of the diamond operator, like so:

    while (defined (my $line = readline( $fh[ $i ] ) ) ) {

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Modified code snippet above.