Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!wuarchive!mit-eddie!uw-beaver!fluke!inc From: inc@tc.fluke.COM (Gary Benson) Newsgroups: comp.lang.perl Subject: Re: Need detab function Keywords: detab Message-ID: <1990Nov21.060849.8066@tc.fluke.COM> Date: 21 Nov 90 06:08:49 GMT References: <1990Nov19.210123.20558@gtisqr.uucp> Organization: John Fluke Mfg. Co., Inc., Everett, WA Lines: 30 In article <1990Nov19.210123.20558@gtisqr.uucp> stu@gtisqr.uucp (Stu Donaldson) 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. > >Any help would be appreciated... > > How about a one liner? :-) > Well it's not a one-liner, and I didn't even write it -- credit Craig Johnson here at Fluke for it: while (/\t/) { $x = index($_, "\t"); $n = 8 - ($x & 7); $spaces = (" " x $n); s/\t/$spaces/; This relies on the unix 8-spaces-per-tab convention. Depending on your exact circumstances, you may need to change the expression in the assignment of $n. For a while, I thought that our emacs had been set up to create and expect 5-space tabs, so Craig changed the third line for me to read: $n = 5 - ($x % 5); -- Gary Benson -=[ S M I L E R ]=- -_-_-_-inc@fluke.com_-_-_-_-_-_-_-_-_-_- If we make peaceful revolution impossible, we make violent revolution inevitable. -John F. Kennedy