http://qs321.pair.com?node_id=204267


in reply to How do you move within an array using foreach?

While not tested, I saw this elegant solution in this node:
print if /\[foo\]/ .. /\[foo2\]/ foreach ( @lines );
Credits go to zigdon... ;-)

Update: Check Ovid's answer; it's more strict in the requirements set.

-- JaWi

"A chicken is an egg's way of producing more eggs."

Replies are listed 'Best First'.
Re: Re: How do you move within an array using foreach?
by jbeninger (Monk) on Oct 10, 2002 at 18:51 UTC
    That looks like a useful thing to have around - I've never seen the /foo/ .. /bar/ notation before - I don't suppose you could explain it, or point me to a place that does?
      It's called the "flip-flop" operator. See perlop
      Look here in perlop.

      In scalar context, ".." returns a boolean value. The operator is bistable, like a flip-flop, and emulates the line-range (comma) operator of sed, awk, and various editors. Each ".." operator maintains its own boolean state. It is false as long as its left operand is false. Once the left operand is true, the range operator stays true until the right operand is true, AFTER which the range operator becomes false again.

      --

      flounder

      As a matter of fact, I can (since about 15 minutes :-)! Summarizing from perlop:

      The two dots work like a sort of flip-flop: if returns true if the first operation (the /foo/ part) evaluates `true' and stays true until the second operation evaluates to `true' (the /bar/ part). After that it returns false again.

      Cheerio,

      -- JaWi

      "A chicken is an egg's way of producing more eggs."

      Look in the perlop documentation, under the "Range Operators" section. All the various uses of .. are explained there in detail.

      -- Mike

      --
      just,my${.02}