in reply to perl one liner to print a line

YAWTDI, this time with no whitespace in the source:

perl -e '{$_=<>;$.<4?redo:print}'

That really does look kinda like line noise. I wouldn't recommend that for serious work, of course.

Replies are listed 'Best First'.
Re^2: perl one liner to print a line
by ikegami (Patriarch) on Dec 12, 2008 at 04:20 UTC

    4 chars shorter:

    perl -ne'print,last,if$.==4' 12345678901234567890123 23

    Update: 5 chars shorter:

    perl -nlE'say,last,if$.==4' 1234567890123456789012 22
        Not equivalent. We spent many chars exiting after four lines. I still have you beat anyway.
      I can save another character if we reintroduce whitespace:
      perl -ne'$.-4or print,last'
      or almost identically:
      perl -ne'$.<4or print,last'

      Update:

      perl -nlE'$.<4or say,last' 123456789 123456789 1 21