If you are processing big files you might want to avoid slurping the whole thing at once. Here the range operator <kbd>...</kbd> comes in handy. When used in a scalar context it returns a boolean and does just what you need here:
while (<DATA>) { if (/$start/.../$end/) { print; } }
I'll try to explain what happens in detail:
The magic is in the three dots: When the first line is processed, the three dots are in the "false" state. They take the expression on the left (<kbd>/$start/</kbd>) and evaluate it. If the expression returns false everything stays the same, the three dots return false. If the expression returns true, the three dots return true and go into the "true" state.
The next time we come to the three dots, the expression on the right is evaluated. If it returns false, everything says the same: the three dots continue to return true. If the expression returns true, the three dots go back into the true state.
But once you've grokked all that, you just think of the whole while + if + ... construct as "from /$start/ to /$end/"
-- Brigitte 'I never met a chocolate I didnt like' Jellinek http://www.horus.com/~bjelli/ http://perlwelt.horus.at
In reply to Re: regex in html + from ... to
by bjelli
in thread regex in html
by voyager
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |