Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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 =)


In reply to Re: Matching strings from three files (three hashes) by bluecompassrose
in thread Matching strings from three files (three hashes) by FluffyBunny

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found