Newsgroups: comp.lang.perl Path: utzoo!utgpu!watserv1!watdragon!rose!ccplumb From: ccplumb@rose.uwaterloo.ca (Colin Plumb) Subject: Re: Help with split, replace and number formats. Message-ID: <1991Feb1.200352.6849@watdragon.waterloo.edu> Sender: daemon@watdragon.waterloo.edu (Owner of Many System Processes) Organization: University of Waterloo References: <1991Jan29.030541.46@eagle.inesc.pt> <1991Jan29.171228.17738@convex.com> <1991Jan30.181924.47@eagle.inesc.pt> Date: Fri, 1 Feb 91 20:03:52 GMT Lines: 29 So you start out with a key string, with some magic letters. You want to build a primary key with the magic letters replaced by other letters and the non-magic ones retained, and a secondary key with the magic letters replaced by others with the non-magic letters deleted. This is easy, with tr/.../.../: $primary = $secondary = $_; $primary ~= tr///; $secondary ~= tr///d; $secondary ~= tr///; $key = $primary . $secondary;; Will that do what you want? Note: it might be a good idea to ensure the first character of the secondary key sorts to less than any possible letter in the primary, with an explicit delimiter (space works well, as does null...) if necessary. This is so (if uppercase letters are magic and their non-magic replacements are lower-case) aBcda -> abcdab aBcd -> abcdb These sort in order abcdab, abcdb, which is equivalent to aBcda, aBcd, which isn't what you eventually want if I understand the problem correctly. -- -Colin