Walter Murray wrote:
> For example, suppose I have procured a voter registration file, in an
> attempt to steal an election. (I've framed my example in political terms
> for those who find such discussions irresistible. :-) Each record contains
> a party field, coded as "D" for Democrat, "G" for Green Party, and "R" for
> Republican. I want to sort the file, and the party field will be one of my
> keys, but I want Republicans to sort first, Democrats next, and Greens last.
> Obviously, neither ascending nor descending order will accomplish this.
>
> In this simple case, it's easy to get around the limitation by doing
> something like mapping the party field to a different encoding that will
> sort as desired, for example, D=2, G=3, R=1. But in the general case, you
> want to be able to compare any two records in an arbitrarily complex manner.
> Are there any sorting utilities on the 3000 that provide this functionality?
> (Plugs are welcome. :-)
SORT.PUB.SYS
ALTSEQ EACH "DGR"="231"
See:
http://tinyurl.com/3rhj4
or the full version of the URL at:
http://docs.hp.com/cgi-bin/fsearch/framedisplay?top=/mpeix/onlinedocs/32650-90499/32650-90499_top.html&con=/mpeix/onlinedocs/32650-90499/00/00/53-con.html&toc=/mpeix/onlinedocs/32650-90499/00/00/53-toc.html&searchterms=altseq&queryid=20041115-104643
If there are any issues with multiple keys and only wanting ALTSEQ on
one of them, try sorting in two steps.
I haven't tested this:
:sort
HP31900A.02.00 TurboSORT MON, NOV 15, 2004, 9:52 AM
(C) HEWLETT-PACKARD CO. 1987
>data is ascii, sequence is ascii
>altseq each "DGR"="231"
>show sequence
nul soh stx etx eot enq ack bel bs ht lf vt ff cr so si
dle dc1 dc2 dc3 dc4 nak syn etb can em sub esc fs gs rs us
sp ! " # $ % & ' ( ) * + , - . /
0 1= R D= 2 G= 3 4 5 6 7 8 9 : ; <
= > ? @ A B C E F H I J K L M N
O P Q S T U V W X Y Z [ \ ] ^ _
` a b c d e f g h i j k l m n o
p q r s t u v w x y z { | } ~ del
I have used ALTSEQ EACH "A-Z" with "a-z" which makes each lower case
char sort immediately after the corresponding upper case char. Very handy.
An example:
:sort
HP31900A.02.00 TurboSORT MON, NOV 15, 2004, 9:50 AM
(C) HEWLETT-PACKARD CO. 1987
>data is ascii, sequence is ascii
>altseq each "A-Z" with "a-z"
>show sequence
nul soh stx etx eot enq ack bel bs ht lf vt ff cr so si
dle dc1 dc2 dc3 dc4 nak syn etb can em sub esc fs gs rs us
sp ! " # $ % & ' ( ) * + , - . /
0 1 2 3 4 5 6 7 8 9 : ; < = > ?
@ [ \ ] ^ _ ` A= a B= b C= c D= d E=
e F= f G= g H= h I= i J= j K= k L= l M=
m N= n O= o P= p Q= q R= r S= s T= t U=
u V= v W= w X= x Y= y Z= z { | } ~ del
Rick
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|