2 # expand and unexpand tabs as per the unix expand and
5 # expand and unexpand operate on arrays of lines. Do not
6 # feed strings that contain newlines to them.
8 # David Muir Sharnoff <muir@idiom.com>
15 Text::Tabs -- expand and unexpand tabs
21 #$tabstop = 8; # Defaults
22 print expand("Hello\tworld");
23 print unexpand("Hello, world");
25 print join("\n",expand(split(/\n/,
26 "Hello\tworld,\nit's a nice day.\n"
31 This module expands and unexpands tabs into spaces, as per the unix expand
32 and unexpand programs. Either function should be passed an array of strings
33 (newlines may I<not> be included, and should be used to split an incoming
34 string into separate elements.) which will be processed and returned.
38 David Muir Sharnoff <muir@idiom.com>
47 @EXPORT = qw(expand unexpand $tabstop);
55 1 while s/^([^\t]*)(\t+)/
57 ($tabstop * length($2)
58 - (length($1) % $tabstop)))
61 return @l if wantarray;
70 @e = split(/(.{$tabstop})/,$x);
76 return @l if wantarray;