how to put "if" within a loop

Discussion in 'Perl Misc' started by Jie, Jul 17, 2007.

  1. Jie

    Jie Guest

    below I am trying to compare if a list of files have common elements
    in certain columns. This code works fine. The problem is that the last
    two line I manually writes the array element. Is there a way to put
    the "if" into a loop, so that I can just use "$lists[$i]" to loop the
    whole thing??

    thanks!

    Jie

    ========my current code=========

    @lists = ("A", "B", "C");
    foreach $list (@lists) {
    %{$list} = (); ## create an empty hash of each element
    open IN, " < pValue_DATA/$list.txt";
    while (<IN>) {
    chomp;
    $_ =~ /(rs\d+)\t([^\t]+)/;
    ${$list}{$1} = $2;
    }
    close IN;
    }

    foreach $SNP (%{$lists[0]}) {
    if ( exists ${$lists[1]}{$SNP} && exists ${$lists[2]}{$SNP}) {
    print OUT "$SNP\t$WGAS_HASH{$SNP}\t${$lists[0]}{$SNP}\t${$lists[1]}
    {$SNP}\t${$lists[2]}{$SNP}\n";
    }
    }
     
    Jie, Jul 17, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. takayuki
    Replies:
    2
    Views:
    294
    Calvin Spealman
    Jun 16, 2008
  2. takayuki
    Replies:
    17
    Views:
    484
    John Salerno
    Jun 17, 2008
  3. addi
    Replies:
    0
    Views:
    293
  4. Jie

    how to put "if" within a loop

    Jie, Jul 17, 2007, in forum: Perl Misc
    Replies:
    3
    Views:
    109
    Brian McCauley
    Jul 20, 2007
  5. Isaac Won
    Replies:
    9
    Views:
    458
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page