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.


In reply to Re: How to switch off the autosplit ? by graff
in thread How to switch off the autosplit ? by jesuashok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.