Just one line of code suffice (not counting the lines in your input string):
my $input = <<"END";
>gavin1
score = 10, evalue = 1000000
length = 50, width = 100
Alignment = plus / minus
>gavin2
score = 20, evalue = 2000000
length = 100, width = 200
Alignment = plus / minus
>gavin 3
score = 60, evalue = 300000
length = 2, width = 50
Alignment = plus / plus
END
print "this is the record you need:\n$1\n" if($input =~ /(>[^>]+plus\s\/\splus)/);
if you know this is always the last record, then /(>[^>]+)$/ would do.
Main Topics
Browse All Topics





by: geotigerPosted on 2005-05-05 at 10:30:07ID: 13938074
Here it is :
s*/si;
lus\s*)
#!/usr/local/bin/perl
#
my $input = <<EoS;
>gavin1
score = 10, evalue = 1000000
length = 50, width = 100
Alignment = plus / minus
>gavin2
score = 20, evalue = 2000000
length = 100, width = 200
Alignment = plus / minus
>gavin 3
score = 60, evalue = 300000
length = 2, width = 50
Alignment = plus / plus
EoS
my $re = qr/>[^>]*plus\s*\/\s*plus\
# print $input;
print "RE = $re\n";
local $\;
my @a = ($input =~ /$re/sg);
for my $i (0..$#a) {
print $a[$i];
}
> ./tst87pat.pl
RE = (?si-xm:>[^>]*plus\s*/\s*p
>gavin 3
score = 60, evalue = 300000
length = 2, width = 50
Alignment = plus / plus