· Offer Kaye > Perl > Reverse Text and Line Order
Explanation of 'Reverse Text and Line Order' Perl oneliner
Here is the code again: perl -e'print scalar reverse<>'
"reverse<>" - since reverse is in the scalar context provided by "scalar", it will return a string consisting of the text of all input
lines reversed.
"print" will print the line returned "reverse".
Note that unless you manually add an empty line at the beginning of the input file, the output printed will not have a
newline ("\n") char at its end, a fact which may or may not bother you... :-)
Usage Example
Given an input file called "example" with the contents:
a1
b2
c3
d4\n (most text editors add a newline to the last line, even if you don't type it)
Then running the following from the command line:
perl -e'print scalar reverse<>' example
will send to "print" the following string:
\n4d\n3c\n2b\n1a
so that "print" will print to STDOUT the following four lines:
4d
3c
2b
1a"your command prompt here without a space beteen it and the '1a'"
Offer Kaye /
To contact me, email me at: offer.kaye no spam at gmail dot com /
Last Modified: Thu Jul 15 23:04:10 2004