in reply to Running a script across multiple directories with multiple output files (problems comparing hash key values)
Hi,
This is the outline of your code
# foreach (@Dirs) # foreach (@Dirs) # for ( 0 .. $#AbsDirs ) # for ( 0 .. $#files ) # for ( 0 .. $#AbsFiles ) # if( $AbsFiles[$c] =~ /R2_001.fastq$/ ) # while(<INPUT1>) # if( @readbuffer == 4 ) # for ( 0 .. $#AbsFiles ) # if( $AbsFiles[$d] =~ /R1_001.fastq$/ ) # while(<INPUT2>) # if( @readbuffer == 4 ) # if( exists( $input1{$key2} ) ) # else
This is how you should write code based on that outline
#!/usr/bin/perl -- use strict; use warnings; use File::Find::Rule qw/ find rule /; use Path::Tiny qw/ path /; my $root = path( grep defined, shift, '.' )->realpath; for my $file ( find( name => qr/R2_001.fastq$/ , in => $root ) ){ OneThing( $file ); } for my $file ( find( name => qr/R1_001.fastq$/, in => $root ) ){ TwoThing( $file ); } exit 0;
After looking closer at your while loops, this is how you should write that
for my $file ( find( name => qr/R2_001.fastq$/, in => $root ) ){ SomeThing( $file ); } exit 0; sub SomeThing { my( $onein) = @_; my $twoin = $onein; $twoin =~ s/R2_001.fastq$/R1_001.fastq/; use Path::Tiny qw/ path /; my $out = path( $onein )->realpath( 'Output.fasta' ); OneTwo( $onein, $twoin , $out ); } sub OneTwo { my( $onein, $twoin, $out ) = @_; if( not path( $twoin )->exists ){ warn qq{Skipping "$onein" because "$twoin" does not exist}; return; } ... }
|
|---|