Perl 5 version 14.3 documentation



Text::Tabs -- expand and unexpand tabs per the unix expand(1) and unexpand(1)


  1. use Text::Tabs;
  2. $tabstop = 4; # default = 8
  3. @lines_without_tabs = expand(@lines_with_tabs);
  4. @lines_with_tabs = unexpand(@lines_without_tabs);


Text::Tabs does about what the unix utilities expand(1) and unexpand(1) do. Given a line with tabs in it, expand will replace the tabs with the appropriate number of spaces. Given a line with or without tabs in it, unexpand will add tabs when it can save bytes by doing so (just like unexpand -a ). Invisible compression with plain ASCII!


  1. #!perl
  2. # unexpand -a
  3. use Text::Tabs;
  4. while (<>) {
  5. print unexpand $_;
  6. }

Instead of the expand comand, use:

  1. perl -MText::Tabs -n -e 'print expand $_'

Instead of the unexpand -a command, use:

  1. perl -MText::Tabs -n -e 'print unexpand $_'


Copyright (C) 1996-2002,2005,2006 David Muir Sharnoff. Copyright (C) 2005 Aristotle Pagaltzis This module may be modified, used, copied, and redistributed at your own risk. Publicly redistributed modified versions must use a different name.