Hello,
I have a large database of words and would like them sorted in reverse order i.e. from the end up.
An example will make this clear:
I have tried to write a program in Perl which basically takes the string from the end and tries to sort from that end but it does not seem to work. I also tried to invoke the scalar reverse function but this does not work.
The data is in an Indic language and is huge: around 300,000 strings.
Any help in the script would be highly appreciated.
Many thanks. Am out and don't have a perl compiler to check the code, but will definitely get back to you with the results.
Thanks for all your help
---------- Post updated at 06:58 AM ---------- Previous update was at 04:14 AM ----------
Many thanks to both. The two solutions worked beautifully. The one proposed by elixir_sinari is faster and as he himself states
With perl (without invoking the interpreter twice and without calling any external utility):
Thanks for the quick postings and the useful code. I learned finally how to handle scalar reverse, which is a great learning experience for me.
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0.8 (lenny)
bash GNU bash 3.2.39
msort 8.44
-----
Input data file data1:
John
Mary
Henry
does
doing
writes
-----
Results, normal key sequencing:
Henry
John
Mary
does
doing
writes
-----
Results, reversed key sequencing:
doing
John
does
writes
Mary
Henry
The msort code was in the Debian repository (as well as Fedora, Ubuntu, and FreeBSD). See site mentioned in script for others.