Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by huck (Prior)
on Aug 08, 2017 at 00:22 UTC ( [id://1196939]=note: print w/replies, xml ) Need Help??


in reply to Running a script across multiple directories with multiple output files (problems comparing hash key values)

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)

  • Comment on Re: Running a script across multiple directories with multiple output files (problems comparing hash key values)
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1196939]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found