You need to set $_ explicitely here.
perl -i -p -e '$_ = <> until $ok || m/RE/; $ok=1' foo
| [reply] [d/l] [select] |
| [reply] |
| [reply] |
Wow ... peek into my brain as I look at your code above:
- Why would that work? What on earth are you trying to do?
- Oh, I see ... hmm, why doesn't that work? It's bizarre, but it should...
- Ah, duh. The magic diamond operator doesn't automatically assign to $_ -- it's the while magic that does that. So you're comparing the REx against the same $_ the whole time, causing an infinite loop.
Even if you did assign your diamond operator to a variable, you're still going to accidentally let the first line of the file through, because it's already been pulled out by the implicit while (<>) { ... } continue { print } that the -p switch gives you. Basically, using the diamond operator inside of a -p or -n script is going to do strange things. I'd avoid it. See my note further down on a non-confusing way to do this :-)
-dlc
| [reply] [d/l] [select] |
| [reply] [d/l] |