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; } ... }

In reply to Re: Running a script across multiple directories with multiple output files (problems comparing hash key values) by Anonymous Monk
in thread Running a script across multiple directories with multiple output files (problems comparing hash key values) by msnyder424

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.