Path: utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!mit-eddie!wuarchive!cs.utexas.edu!sun-barr!ccut!kogwy!wnoc-tyo-news!sranha!sran230!sran84!utashiro From: utashiro@sran84.sra.co.jp (Kazumasa Utashiro) Newsgroups: comp.lang.perl Subject: Re: Need detab function Keywords: detab Message-ID: <244@sran84.sra.co.jp> Date: 21 Nov 90 04:32:40 GMT References: <1990Nov19.210123.20558@gtisqr.uucp> <1990Nov20.175000.1407@iwarp.intel.com> Reply-To: utashiro@sra.co.jp (Kazumasa Utashiro) Organization: Software Research Associates, Inc., Japan Lines: 27 In article <1990Nov20.175000.1407@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: >> | I need a detab function written in perl. I'm sure there must be >> | something other than the brute force method of implimenting this. >> >> Like maybe: >> >> perl -pe '1 while s/\t/" " x (8-length($`)%8)/e' To handle control character correctly, I'm doing like this: 1 while s/\t/" " x (8-&width($`)%8)/e; sub width { local($_)=shift; return(length($_)) unless (/[\033\010\f\r]/); s/^.*[\f\r]//; s/\033\$[\@B]|\033\([JB]//g; # this is for Japanese code 1 while s/[^\010]\010//; s/^\010*//; length($_); } Is there any better way? --- K. Utashiro utashiro@sra.co.jp