7 @EXPORT = qw(expand unexpand $tabstop);
9 use vars qw($VERSION $tabstop $debug);
10 $VERSION = 2007.0711_01;
24 for (split(/^/m, $_, -1)) {
27 $pad = $tabstop - (pos() + $offs) % $tabstop;
35 return @l if wantarray;
47 my $ts_as_space = " "x$tabstop;
49 @lines = split("\n", $x, -1);
51 $line = expand($line);
52 @e = split(/(.{$tabstop})/,$line,-1);
55 unless defined $lastbit;
57 if $lastbit eq $ts_as_space;
62 print "sub on '$x'\n";
66 $line = join('',@e, $lastbit);
68 $x = join("\n", @lines);
70 return @l if wantarray;
81 1 while s/(^|\n)([^\t\n]*)(\t+)/
83 ($tabstop * length($3)
84 - (length($2) % $tabstop)))
87 return @l if wantarray;
94 Text::Tabs -- expand and unexpand tabs per the unix expand(1) and unexpand(1)
100 $tabstop = 4; # default = 8
101 @lines_without_tabs = expand(@lines_with_tabs);
102 @lines_with_tabs = unexpand(@lines_without_tabs);
106 Text::Tabs does about what the unix utilities expand(1) and unexpand(1)
107 do. Given a line with tabs in it, expand will replace the tabs with
108 the appropriate number of spaces. Given a line with or without tabs in
109 it, unexpand will add tabs when it can save bytes by doing so (just
110 like C<unexpand -a>). Invisible compression with plain ASCII!
122 Instead of the C<expand> comand, use:
124 perl -MText::Tabs -n -e 'print expand $_'
126 Instead of the C<unexpand -a> command, use:
128 perl -MText::Tabs -n -e 'print unexpand $_'
132 expand doesn't handle newlines very quickly -- do not feed it an
133 entire document in one string. Instead feed it an array of lines.
137 Copyright (C) 1996-2002,2005,2006 David Muir Sharnoff.
138 Copyright (C) 2005 Aristotle Pagaltzis
139 This module may be modified, used, copied, and redistributed at your own risk.
140 Publicly redistributed modified versions must use a different name.