Hello
Anyone have any experience on perl while loops (I'm a beginner)?
I have a script that needs to use the declared variables outside a the loop, but only one loop is working, even though I have declared the variables outside of the loop, the code is:
my $sample;
my $fastq1;
open(IN, 'ls /*_R1_*.gz |');
while(my $sample = <IN>){
chomp $sample;
print "sample = $sample\n";
my $fastq1="${sample}";
my $sample2;
my $fastq2;
open(IN, 'ls /*_R2_*.gz |');
while(my $sample2 = <IN>){
chomp $sample2;
print "sample2 = $sample2\n";
my $fastq2="${sample2}";
}
}
Sample2 works but sample1 does not, only the first sample is output and then the loop goes onto sample2, the output is:
sample =/sample1_R1_001.fastq.gz
sample2 =/sample1_R2_001.fastq.gz
sample2 =/sample2_R2_001.fastq.gz
sample2 =/sample3_R2_001.fastq.gz
etc..
Can anyone figure this out?
Thanks
Anyone have any experience on perl while loops (I'm a beginner)?
I have a script that needs to use the declared variables outside a the loop, but only one loop is working, even though I have declared the variables outside of the loop, the code is:
my $sample;
my $fastq1;
open(IN, 'ls /*_R1_*.gz |');
while(my $sample = <IN>){
chomp $sample;
print "sample = $sample\n";
my $fastq1="${sample}";
my $sample2;
my $fastq2;
open(IN, 'ls /*_R2_*.gz |');
while(my $sample2 = <IN>){
chomp $sample2;
print "sample2 = $sample2\n";
my $fastq2="${sample2}";
}
}
Sample2 works but sample1 does not, only the first sample is output and then the loop goes onto sample2, the output is:
sample =/sample1_R1_001.fastq.gz
sample2 =/sample1_R2_001.fastq.gz
sample2 =/sample2_R2_001.fastq.gz
sample2 =/sample3_R2_001.fastq.gz
etc..
Can anyone figure this out?
Thanks
Comment