On Mon, 2003-06-16 at 09:40, Michael Campbell wrote: > > A range operator with a regexp works like a flip flop (bistable > > multi > > vibrator or so). The value of the internal flag (and thus the > > result of > > the evaluation) changes in this way: initiallly it's false. If the > > first > > RE matches it's switched to true. It stays true as long as the > > second RE > > does not match. If it does, the flag goes back to false. > > > > while( line = gets ) > > if /BEGIN:VCARD/ =~ line .. /END:VCARD/ =~ line I don't get this syntax. Isn't the last line equivalent to: if (/BEGIN:VCARD/ =~ line) .. (/END:VCARD/ =~ line) which creates at each iteration a new range object, which knows nothing about previous lines or state of the switch. [gus@comp tests]$ irb -v irb 0.7.4(01/05/08) [gus@comp tests]$ irb irb(main):001:0> r = (/BEGIN:VCARD/ =~ line) .. (/END:VCARD/ =~ line) NameError: undefined local variable or method `line' for #<Object:0x353ce0> from (irb):1 irb(main):002:0> line = "toto" "toto" irb(main):003:0> r = (/BEGIN:VCARD/ =~ line) .. (/END:VCARD/ =~ line) ArgumentError: bad value for range from (irb):3 Why does line 3 crashes? What's the difference with your code above, when inside the if statement? Your piece of code works as explained but I can't make sense out of it. Can you shed some light on this please? Guillaume. > > puts line > > end > > end > > > Did perl originate this idea? I remember way back when in perl 4.0x > days when I figured out how that thing worked... it was one of those > "a-HA!" moments. > > Cool operator. > > __________________________________ > Do you Yahoo!? > SBC Yahoo! DSL - Now only $29.95 per month! > http://sbc.yahoo.com >