Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!wuarchive!emory!gatech!mcnc!uvaarpa!mmdf From: worley@compass.uucp (Dale Worley) Newsgroups: comp.lang.perl Subject: Detab function Message-ID: <1990Nov20.182049.12017@uvaarpa.Virginia.EDU> Date: 20 Nov 90 18:20:49 GMT Sender: mmdf@uvaarpa.Virginia.EDU (Uvaarpa Mail System) Reply-To: worley@compass.uucp Organization: The Internet Lines: 26 X-Name: Stu Donaldson I need a detab function written in perl. [...] How about a one liner? :-) This isn't even ugly: perl -pe '$spacing = 8; 1 while s/\t/" " x ($spacing - length($`) % $spacing)/e;' (Amazing! The only other language I know of that can do this in one line is Snobol!) However, the apparently equivalent program perl -pe '$spacing = 8; s/\t/" " x ($spacing - length($`) % $spacing)/eg;' doesn't work, apparently because s///g doesn't work exactly as I expect. I expect it to perform each search and replacement, and then start searching again in the modified string. It appears (if I insert a strategic print) that the successive searches are done in the original string, and all modifications are in a copy of it. (Is this what we really want? Is this documented?) Dale Worley Compass, Inc. worley@compass.com -- It is easier to get forgiveness than permission.