如何使用perl构建管道

时间:2013-10-30 12:21:08

标签: perl wait pipeline

我想使用perl运行一系列系统命令。我写了一个for循环

#!/usr/bin/perl
use warnings;
use strict;
foreach my $ichr (1 .. 21){
    system "bedtools intersect -wb -a genes.bed -b chr$ichr.bed > Counts_chr$ichr.txt";
}

我不确定循环是否会将每个命令提交给系统并启动下一个命令?我希望在开始下一个之前完成一个。 (例如,完成chr1,然后启动chr2,完成chr2,然后启动chr3等。)

如何确保一个命令完成然后启动下一个命令?

1 个答案:

答案 0 :(得分:3)

perldoc -f system
           Does exactly the same thing as "exec LIST", except that a fork
           is done first and the parent process waits for the child
           process to exit.

因此system命令将在继续下一个循环迭代之前等待已启动的进程完成。