You have massive problems with variable scope. A "my" variable only "lives" withing the braces that surround it. Change the top of your file from

#!user/local/perl use Cwd;
to this
#!user/local/perl use strict; use warnings; use Cwd;
And then try to understand what it is telling you. If you still are confused read this Variable Scoping in Perl: the basics. If after that you don not understand how to fix it come back and show us your progress.

hint: the key will be to combine your c/d loops into a single loop. something like this

for my $c (0..$#AbsFiles){ my $key1=undef; my $key2=undef; if ($AbsFiles[$c] =~ /R2_001\.fastq$/){ open INPUT1 ... ; ...stuff to set key1; close INPUT1; } if ($AbsFiles[$c] =~ /R1_001\.fastq$/$/){ open INPUT2 ... ; ...stuff to set key2; close INPUT2; } if (defined($key1) && defined($key2} && key1 eq $key2 ) { ... stuff to do when both are set and equal ... } else { ...stuff to do otherwise .. } } # c

Note that i "escaped" the dot in the regexp. an escaped dot will match any character, while "\." matches a dot itself.

Note that the close does not include the lessthan/greaterthan signs, those are used to read a file, not to reference it. Also note i closed them inside the same scope i opened them, this tends to be good practice.

edit:See below Re: Running a script across multiple directories with multiple output files (problems comparing hash key values)


In reply to Re: Running a script across multiple directories with multiple output files (problems comparing hash key values) by huck
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.