You are re-infventing the range operator. Instead of
if($_=~/$start_pattern/i) { $write_line = 1; } if($_=~/$end_pattern/i) { $write_line = 0; } if($write_line =~ '1') { print "$_\n"; }
You can simply write:
if(/$start_pattern/i .. /$end_pattern/i) { print "$_\n"; }
The if condition is false until the first pattern matches, and remains true until the second pattern matches. Funny things happen if both are true on the same line.
P.S. In your version, you should use numerical comparison, '==', rather than regular expression, '=~'. Regex testing is powerful, but expensive ( slow ), while simple comparison is very fast, but only capable of testing equality.
--
TTTATCGGTCGTTATATAGATGTTTGCA
In reply to Re: Grabbing part of an HTML page
by TomDLux
in thread Grabbing part of an HTML page
by kingdean
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |