First use I've ever found for the perl range operator:
perl -ane '// .. /Reverse Provides/ or print $F[0], "\n"'
Στις 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[0], "\n"'
perl -ane '$a && print; /foo/ and $a=1'
George Bouras <foo@example.com> writes:
Στις 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[0], "\n"'
This does not print lines matching the right pattern in the range, so it
does not do exactly what the subject line says.
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.
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.
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
George Bouras <foo@example.com> writes:
Στις 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[0], "\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.
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]
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.
perl -ane '// .. /Reverse Provides/ or print $F[0], "\n"'
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.
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
[...]
perl -ane '// .. /Reverse Provides/ or print $F[0], "\n"'
[...]
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.
Thanks for pointing this out: The difference (start printing after the
first Reverse Provides and omit all later lines containing this text)
doesn't matter for my use-case but technically, what I wanted was
1 .. /Reverse Provides/
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 53:08:45 |
Calls: | 6,712 |
Files: | 12,243 |
Messages: | 5,355,264 |