user1007742
user1007742

Reputation: 571

how to build a pipeline using perl

I would like to run a series of system command using perl. I wrote a for loop

#!/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";
}

I am not sure whether the loop will submit each command to the system and start the next one? I want one to finish before it starts the next one. (e.g., finish chr1, then start chr2, finish chr2, then start chr3 . etc)

How can i make sure that one command finished and then start the next one?

Upvotes: 0

Views: 517

Answers (1)

Lajos Veres
Lajos Veres

Reputation: 13725

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.

So the system command will wait for the started process to finish before it continues the next loop iteration.

Upvotes: 3

Related Questions