Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!sol.ctr.columbia.edu!spool.mu.edu!uunet!mcsun!inesc!eagle!jmc From: jmc@eagle.inesc.pt (Miguel Casteleiro) Newsgroups: comp.lang.perl Subject: Re: Help with split, replace and number formats. Message-ID: <1991Jan30.181924.47@eagle.inesc.pt> Date: 30 Jan 91 18:22:08 GMT References: <1991Jan29.030541.46@eagle.inesc.pt> <1991Jan29.171228.17738@convex.com> Sender: news@inesc.UUCP Organization: INESC/P1714, Lisboa, Portugal Lines: 122 Nntp-Posting-Host: eagle In article <1991Jan29.171228.17738@convex.com> tchrist@convex.COM (Tom Christiansen) writes: >From the keyboard of jmc@eagle.inesc.pt (Miguel Casteleiro): >:Hi there! > >Bom Dia! Voce^s conhecem Perl no Portugal???? ^^em Sim, e mais algumas coisitas! >:1) I need to split the following line: >: >: "This is a line ( test,with ugly typing." >: >:into the array: >: >: ('"This','is','a','line','(','test,','with','ugly','typing."') >: > [some ways off do it deleted] > >2) You can munge the data first to fix the ugly typing: > s/,(\S)/, $1/g; > and now split on white space as usual. This seems best to me > of these three approaches. I'll use this approach. It seems to work fine. Thanks! >:2) I need to replace the word: 'teste' >: by the word: 'aebtecd' >: >:In this replace operation the character 't' gets replaced by 'a' >:and 'c' is appended to the word, and the character 's' is replaced >:by 'b' and 'd' is appended to the word. >:I need this strange replace to use a 7-bit sort to sort 8-bit >:(ISO-8859-1) text. >:What I need is to translate some characters by some others, and >:for each character translated I need to append a character to the >:string (something like: tr/ts/ab/cd/ :-). >:Is there an easy way to do this? > >I ask myself which 7-bit ascii sort you're using, and why the existing >sorts don't work for 8-bits. It's the collating sequence, right? I'm using 7-bit and 8-bit sorts and none of them do what I want! The test I gave was incorrect, sorry :-( What I want is to replace the word 'teste' by the word 'aebaecdc'. I'll explain better what I want. Let's say that "A" is an "a" with a grave accent and "B" is an "a" with an acute accent. So, the sorting order will be (at least for the portuguese): a A B b c d e f ... So, I will have the following sorted words: Aac abc Abc acbd Please note that "a" = "A" = "B" only if the words are different (not counting the characters "a", "A" and "B"). If they are equal then "a" < "A" < "B". To accomplish this, the best way I can think of, is to replace: "a" by "a" and append "a" "A" by "a" and append "b" "B" by "a" and append "c" So, a 7-bit sort will see the previous words as: aacba abca abcb acbda and will sort properly. The code I'm using to do this is: $word = "Aac"; $_ = $word; tr/aAB/aaa/; $sword = $_; $_ = $word; tr/aAB//c; tr/aAB/abc/; $sword .= $_; and $sword will be 'aacba'. If there is an easy way to do this, please let me know. Also, if someone can think of a better way to sort 8-bit text, please let me know. > [ A solution for the 'teste' example deleted ] > >:3) Finally, is there an easy way to print numbers in the form: >: >: 12345678.12 -> 12,345,678$12 > > $_ = '12345678.12'; # note quotes!!! > > s/\./\$/; > 1 while s/(.*\d)(\d{3})/$1,$2/; > > result -> "12,345,678$12" I'll use this code, Thanks! > [ A solution for the euronotation deleted ] > >--tom > always wanted!" --me (Tom Christiansen ) -- __ Miguel Casteleiro at __ /// INESC, Lisboa, Portugal. "News: so many articles, \\\/// Only Email: jmc@eagle.inesc.pt so little time..." \XX/ Amiga