in reply to Re: Read, match string and print
in thread Read, match string and print

Ah, okay. I thought of it as follows. I initialized these variables in the beginning and set them to empty. In the end, I wanted to print if and only if all of these variables are assigned values (which were supposed to be read from the file). Thus, I thought it might work if I tell Perl to expect them as defined. But it did not work. :) Thank you for the code! (It did not occur to me that I should have set them as undef before going for any loop)
5555555 123456789 join(11111..222222,333333..444444) 10101010 123456789 join(66666..7777777,888888..99999)
It fails to put a tab between the very first and second elements. Do you know why this is the case?

Replies are listed 'Best First'.
Re^3: Read, match string and print
by jwkrahn (Abbot) on Feb 08, 2010 at 09:00 UTC

    I don't know.    When I tried it, it worked.

      Thanks once again. Yes, it is working but it is getting the wrong input and hence prints out incorrectly.
      /protein_id="NP_12312" /db_xref="GI:7546536"
      Here. in order to get the GI number, I use this matching expression elsif ( /^\s*protein_id\S*\n\s*\Sdb_xref="GI:(\d+)/ ) but it is not matching. Am I doing some fundamental mistake with the matching operators?

        In the other code posted here, I see that you're reading the file line by line. You can't match more than one line if you're reading/processing each line separately. You will need to either set a flag or collect all information up to a point where you know that the current set of data has ended (for example because you hit the start of the next gene or EOF), and then process the accumulated data.