in reply to Doing two things at once, fork question.
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Doing two things at once, fork question.
by mhearse (Chaplain) on Mar 07, 2008 at 22:08 UTC | |
by BrowserUk (Patriarch) on Mar 07, 2008 at 22:36 UTC | |
by tye (Sage) on Mar 07, 2008 at 23:25 UTC | |
by BrowserUk (Patriarch) on Mar 07, 2008 at 23:52 UTC | |
by tye (Sage) on Mar 08, 2008 at 03:00 UTC | |
|