With threads:
#! perl -slw use strict; use threads; use threads::shared; my @output :shared; my $pid :shared; my $t = async { $pid = open CMD, qq[ perl -le"\$|++; print ~~localtime while sleep 1" |] or die $!; while( <CMD> ) { chomp; lock @output; push @output, $_; } close CMD; }; sleep 10; ## do other stuff for my $out ( do{ lock @output; @output } ) { if( $out =~ m[6] ) { print $out; } } kill 9, $pid; $t->join;
In reply to Re: Doing two things at once, fork question.
by BrowserUk
in thread Doing two things at once, fork question.
by mhearse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |