start page | rating of books | rating of authors | reviews | copyrights

Programming Perl

Programming PerlSearch this book
Previous: 7.2.69 Text::Soundex - The Soundex Algorithm Described by Knuth Chapter 7
The Standard Perl Library
Next: 7.2.71 Text::Wrap - Wrap Text into a Paragraph
 

7.2.70 Text::Tabs - Expand and Unexpand Tabs

use Text::Tabs;  $tabstop = 8;                            # set tab spacing to 8 (default) print expand("Hello\tworld");            # convert tabs to spaces in output print unexpand("Hello,        world");   # convert spaces to tabs in output $tabstop = 4;                            # set tab spacing to 4 print join("\n", expand(split(/\n/,                 "Hello\tworld, \nit's a nice day.\n")));

This module expands tabs into spaces and "unexpands" spaces into tabs, in the manner of the UNIX expand (1) and unexpand (1) programs. All tabs and spaces - not only leading ones - are subject to being expanded and unexpanded.

Both expand() and unexpand() take as argument an array of strings, which are returned with tabs or spaces transformed. Newlines may not be included in the strings, and should be used to split strings into separate elements before they are passed to expand() and unexpand() .

expand() , unexpand() , and $tabstop are imported into your program when you use this module.


Previous: 7.2.69 Text::Soundex - The Soundex Algorithm Described by Knuth Programming Perl Next: 7.2.71 Text::Wrap - Wrap Text into a Paragraph
7.2.69 Text::Soundex - The Soundex Algorithm Described by Knuth Book Index 7.2.71 Text::Wrap - Wrap Text into a Paragraph