Dear Monks,

I have an array containing pairs of numbers. I then have three other arrays containing the original numbers. I simply want to find out which array each half of the pair came from. I have this code but wondered if there was a better way of doing it?

Hope you can help!

# @gene_pairs contains the pairs of numbers e.g, 1304 1509 # @rep1_pids, @rep2_pids and @rep3_pids are where the numbers came fro +m. foreach my $pair (@gene_pairs) { my @pair = $pair; my $p = join ('', @pair); @pair = split (/\t/, $pair); + + + for (my $i=0; $i<@rep1_pids; $i++) { if ($pair[0] == $rep1_pids[$i]) { push @locations, "rep1 "; push @new_gp, "$rep1_pids[$i] "; } + + if ($pair[1] == $rep1_pids[$i]) { push @locations, "rep1 "; push @new_gp, "$rep1_pids[$i] "; } } for (my $i=0; $i<@rep2_pids; $i++) { if ($pair[0] == $rep2_pids[$i]) { push @locations, "rep2 "; push @new_gp, "$rep2_pids[$i] "; } if ($pair[1] == $rep2_pids[$i]) { push @locations, "rep2 "; push @new_gp, "$rep2_pids[$i] "; } } for (my $i=0; $i<@rep3_pids; $i++) { if ($pair[0] == $rep3_pids[$i]) { push @locations, "rep3 "; push @new_gp, "$rep3_pids[$i] "; } if ($pair[1] == $rep3_pids[$i]) { push @locations, "rep3 "; push @new_gp, "$rep3_pids[$i] "; } } } print "@new_gp\n"; my (@paired_genes1, @paired_genes2); my @pairs2 = @new_gp; print "@pairs2\n"; while (my ($one, $two) = splice(@pairs2,0,2)) { #print "$one ---- $two\n"; push @paired_genes1, "$one "; push @paired_genes2, "$two "; }

In reply to extracting information from arrays by Anonymous Monk

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.