Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: regex in html + from ... to

by bjelli (Pilgrim)
on Apr 02, 2001 at 13:39 UTC ( #68965=note: print w/ replies, xml ) Need Help??

in reply to regex in html

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

Comment on Re: regex in html + from ... to
Download Code
Re: Re: regex in html + from ... to
by AidanLee (Chaplain) on May 04, 2001 at 17:18 UTC

    The Camel 2nd Ed. States that the range operator is two dots '..' not three.


      It can be both .. and .... They have subtly different effects.

      With two dots, it's possible for both the start and end checks to be true on the same line. This means that the operator goes from false to true and back to false again on one evaluation. With three dots, if the start check is true, then the end check isn't checked until the next evaluation - thus forcing at least one iteration with the operator returning true.


      "Perl makes the fun jobs fun
      and the boring jobs bearable" - me

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://68965]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2014-07-13 01:39 GMT
Find Nodes?
    Voting Booth?

    When choosing user names for websites, I prefer to use:

    Results (244 votes), past polls