use a list to extract out the data...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • liebesie
    New Member
    • May 2010
    • 3

    use a list to extract out the data...

    Hi,
    I'm new to Perl... I have some questions to extract the data out.
    I have two files. One is gene list, and the other is the whole data(having gene lists and other values).
    I'd like to extract the informations of the input lists.

    I tried... but the RESULT file is empty!! I don't know what's wrong...
    Here is my code.


    Code:
    #!/usr/bin/perl 
    
    open(Data,"data.txt");
    @all = <Data>;
    close(Data);
    
    open(List,"list.txt");
    @list = <List>;
    close(List);
    
    open(ANS,">result.txt");
    
    for($j=0;$j<$#list;$j++){
        
        chomp($list[$j]);
    
                   }
    
    for($i=0;$i<$#all;$i++){
    
        @b=split("\t",$all[$i]);
    
       for($j=0;$j<$#list;$j++){
        
        if($b[0] eq $list[$j]){
    
            print ANS "$all[$i]"; 
    
                   }
             }
    }
    
    close(ANS);






    Thanks!!!
  • toolic
    Recognized Expert New Member
    • Sep 2009
    • 70

    #2
    Since you didn't show any input data, you must debug your own code. Follow the tips in the Perl Basic debugging checklist.

    Specifically, you should check the success of each file open, then start adding print statements to your code.

    Comment

    • liebesie
      New Member
      • May 2010
      • 3

      #3
      Hi,
      here are my file contents(.jpg).
      i've tried use the debugging checklist;
      however, it didn't show anything.
      Attached Files

      Comment

      • RonB
        Recognized Expert Contributor
        • Jun 2009
        • 589

        #4
        You're using the wrong data structure. Instead of 2 arrays, you should use 1 hash.

        Load data.txt into a hash where the gene is the key and the value is the related data.

        Then loop over list.txt and check if the gene is a key in the hash. If it is, then output the data.

        Comment

        • liebesie
          New Member
          • May 2010
          • 3

          #5
          hi,
          i'm really new to Perl. i can't really understand, but i have tried...
          here is my code, please tell me where is the problem.


          Code:
          #!/usr/bin/perl
          
          open(Data,"<data.txt");
          my %all= <Data>;
          my ($key, $value);
          
          open(List,"<list.txt");
          my %list = <List>;
          
          open(ANS,">result.txt");
          
          while($all{$key} eq %list) {
          
                  print ANS "%all"; 
          
                         }
          
          close(Data);
          close(List);
          close(ANS);
          Last edited by numberwhun; May 23 '10, 01:48 AM. Reason: Please use CODE TAGS!

          Comment

          • RonB
            Recognized Expert Contributor
            • Jun 2009
            • 589

            #6
            It doesn't appear that you understand the basics, so you probably wouldn't understand my descriptions on what you're doing wrong.

            You need to start by getting a good beginner level Perl book.

            Learning Perl, Fifth Edition

            Comment

            Working...