Rainer Weikusat <rwei...@talktalk.net
> Ben Bacarisse <ben.u...@bsb.me.uk
>> George Bouras <f...@example.com
>>> Στις 9/2/2021 11:10 μ.μ., ο/η Rainer Weikusat έγραψε:
>>>> First use I've ever found for the perl range operator:
>>>> perl -ane '// .. /Reverse Provides/ or print $F, "\n"'
>> This does not print lines matching the right pattern in the range, so it
>> does not do exactly what the subject line says.
> The subject says "everything after" and that's what it does: The
> separator is not supposed to be included.
I think there is some ambiguity in the wording.
$ cat t
$ perl -ane '// .. /x/ or print $F, "\n"' t ✘
I assumed you'd want the second x line printed since it follows a match,
but of course it is also, at the same time, a match itself.
>> It took me a while to work out what's really going on because the use of
>> //, with it's special meaning, makes the whole thing a bit too tricksy
>> for me (and I like tricksy!). I'm still not sure what Perl says about
>> using m// before any match has succeeded.
> If no match has previously succeeded, this will (silently) act instead
> as a genuine empty pattern (which will always match).
> [perldoc perlop]
Ah, thanks. I searched but could not find that. Maybe I only looked
>>> perl -ane '$a && print; /foo/ and $a=1'
>> I think this is clearer (though I might use a name like $seen rather
>> than $a) and it does do exactly what the subject line says.
> It's obviously possible to imitate the built-in operator using a
> (miniature) state machine. But as there's a built-in operator which can
> serve the exact same function (and one I haven't found any use for so
> far), I considered this more worth of writing about it.
If you want the behaviour that you actually get with //../pattern/ then
this code is not equivalent. I agree that the state-machine equivalent
of the original would be messier.