Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Matching strings from three files (three hashes)

by bluecompassrose (Initiate)
on Aug 17, 2010 at 20:45 UTC ( #855607=note: print w/replies, xml ) Need Help??


in reply to Matching strings from three files (three hashes)

The issue was that the Amp variable, when compared to the size of the others, would go OOB due to the way the $ID was referenced.

I fixed up the code by assigning a separate array for the variable, and then using a loop, like so

my @Amp = (); #Setting up a dynamic Array due to changes in amounts of + possible cell ID's my @Amps = (); #Setting up a dynamic array for the sequences under the + IDs my $n = (0); #Array spacer. Not a local variable; used later in execu +tion. my $file2 = shift; open (FILE2, "$file2")|| die "Failed to open $file2 for reading : $!"; + # Open first file local $/= ">"; my $first=<FILE2>; while (<FILE2>) { # Reading first hash chomp; my ($ID, $Seq) = split("\n"); $Amp[$n] = $ID; #Only need the ID. Sequence can be added to a dif +ferent array in a similar fashion $Seq =~ tr/acgt/ACGT/; $Amps[$n] = $Seq; #As Above, but the sequence $n++; #Increases array holder } close FILE2 || die "Failed to close $file2 : $!"; ... ... my $m = (0); #New variable to check against Amp while ($m < $n){ #while there remain more Amp ID's to check. Not usin +g <= due to how array and perl interact. foreach my $ID (keys %bwa){ #for each ID ... } $m++; }

I realize this isn't the prettiest solution, but its worked well enough with only two different "$ID" strings in input 2. If any monks know of a neater solution, please go ahead =)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2020-10-20 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (208 votes). Check out past polls.

    Notices?