Path: utzoo!censor!geac!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!uunet!samsung!sdd.hp.com!usc!julius.cs.uiuc.edu!apple!sun-barr!newstop!texsun!convex!news From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: Help with split, replace and number formats. Message-ID: <1991Jan29.171228.17738@convex.com> Date: 29 Jan 91 17:12:28 GMT References: <1991Jan29.030541.46@eagle.inesc.pt> Sender: news@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 102 Nntp-Posting-Host: pixel.convex.com From the keyboard of jmc@eagle.inesc.pt (Miguel Casteleiro): :Hi there! Bom Dia! Voce^s conhecem Perl no Portugal???? :I have some problems that I need to solve so I can finish some :perl scripts. : :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."') : :Please note the punctuation characters. :Is there a split pattern to do this? Well....... I can think of a several ways off the top of my head: 0) You can split on /([\s,]+)/ and retain the delimiters and then run back through the array and merge the ones that are commas and toss those that aren't. Ug. 1) You could first simply split on white space, and then run back through the array looking for \S,\S and splitting those, but retaining the comma. Kinda ug. 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. :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? For your example, I did this: $_ = 'teste'; $_ .= 'c' x s/t/a/g; $_ .= 'd' x s/s/b/g; print "result is $_\n"; or with a different variable: $foo = 'teste'; $foo .= 'c' x ($foo =~ s/t/a/g); $foo .= 'd' x ($foo =~ s/s/b/g); print "result is $foo\n"; But that yields 'aebaeccd', not what you said you wanted. Did you not want all the t's translated? If you only want the first one, the /g should be removed. :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" or in euronotation: $_ = '12345678.12'; s/\./\,/; 1 while s/(.*\d)(\d{3})/$1.$2/; # result -> "12.345.678,12" The quotes are so we don't have problems going into floating point notation. This would also help first: $_ = sprintf("%10.2f", $_); # discard boring bits --tom -- "Hey, did you hear Stallman has replaced /vmunix with /vmunix.el? Now he can finally have the whole O/S built-in to his editor like he always wanted!" --me (Tom Christiansen )