in reply to Pattern Match Issue
use strict; use warnings; local $/; my ($name, $aa); while (my $seq = <DATA>) { if ($seq =~ />(\w+).+aa\)\n(\w+)/m) { $name = $1; $aa = $'; } } print "$name $aa\n"; __DATA__ >CIMG_12545 | Coccidioides immitis RS hypothetical protein (translatio +n) (95 aa) MSSQPTTLQSQTGIQRHGEISSQAQKPTTALEEDDEFEDFPVEDWPQEDAEALGPAGTNN DHLWEESWDDDDSNEEFSRQLKEELKKVEAMKQQ*
A side note, while (my $seq = <$IN2>) { is a bad structure to get into the habit of using, since it will exit your loop if the line evaluates to false - i.e. if you have a blank line in your file. Better would be while (defined (my $seq = <$IN2>)) {. See almut below.
Update: I should mention that for what you've written the m modifier on your regular expression has no impact. As it states in Modifiers, m modifies the matching behavior of ^ and $ so they match new lines. You don't have either metacharacter in your expression, so the modifier is unnecessary.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pattern Match Issue
by almut (Canon) on Nov 23, 2009 at 21:24 UTC |