reverse (retrograde) sorting under F9

Ideas for new features

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Arnoud van den Eerenbeemt
Posts: 5
Joined: Fri Jul 20, 2007 11:55 am

reverse (retrograde) sorting under F9

Post by Arnoud van den Eerenbeemt »

As a Dutch lexicographer and developer of medical dictionaries and a medical spellchecker, I use TextPad for coding and sorting lexical data. I would be greatly helped with an option under F9 for sorting lines in reverse order (retrograde). Is this an option that will be appreciated by others too and could it possibly be included in a future version? For this purpose I now have to resort to WordSmith, a linguistic tools suite that requires a lot of data preprocessing before obtaining the desired result.
Regards,
Arnoud
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Does Tools/Sort/Descending not work?
Hope this was helpful.............good luck,
Bob
Arnoud van den Eerenbeemt
Posts: 5
Joined: Fri Jul 20, 2007 11:55 am

reverse (retrograde) sorting under F9

Post by Arnoud van den Eerenbeemt »

Hi Bob,

Thanks for suggesting. No, that is not what I mean. Consider:
- ascending sorting: Bob | Dick | Harry | John | Paul
- descending sorting: Paul | John | Harry | Dick | Bob
- sorted reversely, you would get: Bob | Dick | Paul | John | Harry, based on the names' last letters, here resp. b, k, l, n, y.
Regards,
Arnoud
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

In Perl:

Code: Select all

print sort { ( reverse $a ) cmp ( reverse $b ) } <> ;
although that won't scale well for very large files.
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Thanks for sample of retrograde.

Will whole line be in retrograde or each word?
Hope this was helpful.............good luck,
Bob
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Ah, I see.

To sort the |-separated items on each line you might need something like:

Code: Select all

for my $line ( <> )
{
  chomp $line ;
  $line =~ s/ +$// ;
  my @elems = split ' *\| *', $line ;
  my @sortedElems = sort { ( reverse $a ) cmp ( reverse $b ) } @elems ;
  my $sortedLine = join ' | ', @sortedElems ;
  print "$sortedLine\n" ;
}
No problems there with scalability.
Arnoud van den Eerenbeemt
Posts: 5
Joined: Fri Jul 20, 2007 11:55 am

Post by Arnoud van den Eerenbeemt »

Gentlemen, thanks for your attempt to help me out. Alas, I am no Perl programmer, so this code is abacadabra to me. Will this input enable/motivate Helios to include reverse sorting in a future update of TextPad?
Sincerely, Arnoud
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

I doubt it; this is a very special-purpose requirement. If every such special need were catered for directly, TextPad's code and user interface would bloat hugely.

If your work involves much text handling you will find it extremely useful to have at your disposal a general-purpose language with powerful text handling facilities, such as Perl, Python, Ruby, Tcl, or what you will. Otherwise you will always be restricted to whatever was thought of or thought to be important by the author of the limited-functionality tools you use.

Unfortunately, TextPad does not support the writing of scripts in any language. Requirements like yours are a good argument for the inclusion of this functionality.

BTW, why do you want to order words (or lines) in this way?
varav
Posts: 1
Joined: Tue Nov 15, 2011 2:34 am

Post by varav »

(Yes, I realize this is a VERY old thread)

given this list of names:
bob
cindy
mel
barbara
gene

find ------------ ^(.*)(.)$
replace --------- \2 \1\2
take note of the SPACE following the initial "backslash two"
ReplaceAll

the result:
b bob
y cindy
l mel
a barbara
e gene

Next, Tools } Sort produces:
a barbara
b bob
e gene
l mel
y cindy

Then
find ---------- ^.[ ]
replace ---------- leave empty
ReplaceAll

Now we have the "retrograde sorted" list:
barbara
bob
gene
mel
cindy
Post Reply