in reply to Re: How to replace Tab with spaces not altering postion
in thread How to replace Tab with spaces not altering postion
The problem is it's using $` which incurs a huge performance penalty.
Here's another OWTDI:
$_ = join "", map { $_ . " " x (8 - length() % 8) } split /\t/, $_, -1; Update: blakem points out that this code is broken. It will pad all parts of the string to a multiple of 8, including the last one. Getting it not to is disappointingly awkward..(Update is untested.)$_ = join "", do { my @bits = split /\t/, $_, -1; (map { $_ . " " x (8 - length() % 8) } @bits[0..$#bits-1]), $bits[ +-1] };
Makeshifts last the longest.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re^2: How to replace Tab with spaces not altering postion
by petral (Curate) on Oct 14, 2002 at 15:27 UTC | |
by Aristotle (Chancellor) on Oct 14, 2002 at 15:33 UTC | |
by petral (Curate) on Oct 15, 2002 at 15:01 UTC |