in reply to What's the "...0" mean?

Thanks for that, guys.

However, I'm still not clear on the practicalities of this in the context of my example.

If the input file is:

zabcz zzabczz zzzabczzz

And I run the one-liner:

perl -ne 'print if s/.*?(?=abc)//...0' <infile

I get this output:

abcz zzabczz zzzabczzz

If I change it to "...1", I get the *same* output. Why?

If I change it to "...2", I get this output:

zabcz zzabczz abczzz

What's going on?

Replies are listed 'Best First'.
Re^2: What's the "...0" mean?
by JavaFan (Canon) on Oct 15, 2010 at 05:25 UTC
    If .. or ... in used scalar context, and one of the arguments is a numerical literal (as is the case here), there's an implicit comparison against $. is made. So, in the given examples, after matching the left hand side of ..., $. equals 1. So, before the right hand side is tested, $. equals 2. Hence, ...0 or ...1 will never match, but ...2 will.

      Thanks JavaFan (brave name for a Perl forum),

      > Hence, ...0 or ...1 will never match, but ...2 will.

      But "...0" and "...1" seem to have matched the 1st line of the input file, where they changed "zabcz" to "abcz", right?

      Why did they both match the 1st line, but "...2" matched the 3rd line?

        The part before the dots turns the flip flop operator to true, the part after sets it to false when it matches.

        An example of how the flip flop operator works.

        my @array = qw- 1 2 3 on 4 5 off 6 7 8 on 9 10 11 12 off 13 14 15 -; for (@array){ say if /on/ ... /off/; }
        Update: Added example.