in reply to How to replace Tab with spaces not altering postion
and this from perlop:> perldoc -q tabs Found in /usr/local/lib/perl5/5.6.1/pod/perlfaq4.pod How do I expand tabs in a string? You can do it yourself: 1 while $string =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e; Or you can just use the Text::Tabs module (part of the standard +perl distribution). use Text::Tabs; @expanded_lines = expand(@lines_with_tabs); >
And this has been in the perl man page since perl1!Occasionally, you can't use just a `/g' to get all the changes to occur that you might want. Here are two common cases: # put commas in the right places in an integer 1 while s/(\d)(\d\d\d)(?!\d)/$1,$2/g; # expand tabs to 8-column spacing 1 while s/\t+/' ' x (length($&)*8 - length($`)%8)/e;
print "\et" x ($tab/8), ' ' x ($tab%8); # tab over
  p
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to replace Tab with spaces not altering postion
by Aristotle (Chancellor) on Oct 11, 2002 at 21:45 UTC | |
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 |
In Section
Seekers of Perl Wisdom