You can do it like this:
$ perl -e 'print +(<>) x 4'
This removes the -n
loop from your code, and instead reads the entire STDIN
in one go. We need the parentheses ()
to get the read operator into list context, so it reads all lines at once. The +
tells the perl interpreter that the parentheses are a list, and not part of the print
(as print()
). Finally the repeat operator x
in list context repeats the entire list.
$ cat foo
0
1
$ cat foo | perl -e 'print +(<>) x 4'
0
1
0
1
0
1
0
1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…