これは の良い使用例のように思えますForks::Super::bg_qx
。
use Forks::Super 'bg_qx';
$output = bg_qx $bashcommand;
$output1 = bg_qx $bashcommand1;
$output2 = bg_qx $bashcommand2;
$output3 = bg_qx $bashcommand3;
これら 4 つのコマンドをバックグラウンドで実行します。戻り値 ( 、 など) に使用される変数$output
は$output1
、オーバーロードされたオブジェクトです。プログラムは、次にこれらの変数がプログラムで参照されるときに、これらのコマンドからの出力を取得します (必要に応じて、コマンドが完了するのを待ちます)。
... more stuff happens ...
# if $bashcommand is done, this next line will execute right away
# otherwise, it will wait until $bashcommand finishes ...
print "Output of first command was ", $output;
&do_something_with_command_output( $output1 );
@output2 = split /\n/, $output2;
...
2012-03-01 更新: Forks::Super の v0.60 には、リスト コンテキストで結果を取得できるいくつかの新しい構造があります。
if ($condition) {
tie @output, 'Forks::Super::bg_qx', $bashcommand;
tie @output1, 'Forks::Super::bg_qx', $bashcommand1;
tie @output2, 'Forks::Super::bg_qx', $bashcommand2;
tie @output3, 'Forks::Super::bg_qx', $bashcommand3;
}
...