You could always do it manually.
perl -ne 'BEGIN{$autosplit = 1} @F=split(" ") if $autosplit; $value = pop(@F); if ( $value == 0 ) { $autosplit = 0 } else { print @F[0 .. 2] }'
| [reply] [d/l] |
I don't quite understand the point of your question. When you use "-an" on the command line, you still have access to each complete line of input, via $_, as well as having access to the whitespace-delimited tokens via @F. So, if you want some event in the data to trigger a switch from using @F to using just $_, you can still use "-a".
But your example is unclear, because it looks like you just want to stop doing whatever you were doing when the first value on a line happens to equal 0 (so why not just exit at that point?) Anyway, here's another way to do it:
perl -ane 'BEGIN{$auto=1} $auto=0 if($F[0]==0); if($auto){print @F[0..
+2]} else{ }'
I would expect that you would normally be putting something in that "else" block involving $_ ...
If it's a question of "optimizing" (saving perl from doing all that work on splitting lines), then avoiding "-a" as suggested in the first reply will be the way to go. But usually, optimization is not much of an issue in one-liners like this. | [reply] [d/l] |