12
23
34
45
56
67
1223
3445
5667
perl -pe 'chomp if $. % 2' file
perl -pe 'chomp; $_ .= <>' file
perl -lpe '$\=--$|?$,:$/' file
--$| toggles between 1 and 0. It is this variable's behavior when (--$| or $|--)
$| is initially 0. (NOTE: this behavior doesn't happen with ++$| or $|++).
-l chomps the line input and, for when --$| == 1, prints with $\ = $,
($, is by default the empty string). When --$| == 0, prints with $\ = $/
($/ is by default = "\n").
-p applies 'print()' as the last statement in the implicit 'while( ... )' loop
So. in effect, on the first line in, chomps the line. Then, since $|==1 in the first
iteration, prints with a line end equal to $, (by default, the empty string).
In the next line, $| will equal 0, so the print will end with $/ (default value of "\n")
perl -lpe '$\=--$|?$,/' file
perl -pe 'chomp; $_ .= <>' file
perl -lpe '$\=--$|?$,/' file
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |