Perl Range operator paradigm

Martien Verbruggen mgjv at tradingpost.com.au
Mon Oct 22 14:40:27 CEST 2001


On Tue, 16 Oct 2001 12:27:26 +0200,
	Laurent Pierron <Laurent.Pierron at loria.fr> wrote:
> Hello Gurus,
> 
> In Perl there is a very powerful range operator '..', which, in scalar
> context, is acting like line-range (,) operator in sed and awk.
> 
> By example, this small program prints all the lines in the file included
> between <BODY>...</BODY> :
> 
> while (<>) {
>    if (/<BODY>/ .. /<\/BODY>/) {print; }
> }

Sorry to barge in, but that iperator, in this context, isn't the range
operator, but the flip-flop [1]. Without more information, the python
people here probably won't know what to look for. The way the flip-flop
works is that the result of the expression A..B becomes true when A is
true and stays true until B is true, after which the whole cycle can
start again.

The above loop would print all blocks of text between all lines that
match the regular expressions above, including the lines themselves. 

If I knew the answer to how to do this in python, i'd include it, but
I'm still reading up on the language.

Martien

[1] In other contexts the same operator is indeed called the range
operator, and it produces lists of consecutive values.
-- 
                                | 
Martien Verbruggen              | That's funny, that plane's dustin'
                                | crops where there ain't no crops.
                                | 



More information about the Python-list mailing list