Text::Tabs(3perl)
β¨ Text::Tabs β¨
okay bestie, real talk: this is Text::Tabs, a page from the Perl Programmers Reference Guide, and it's here to help you expand and unexpand tabs just like the Unix expand(1) and unexpand(1) commands do. yes, the same energy, but in Perl. π
πΈ NAME πΈ
Text::Tabs β expand and unexpand tabs like unix expand(1) and unexpand(1) π
π¦ SYNOPSIS π¦
use Text::Tabs;
$tabstop = 4; # default = 8
@lines_without_tabs = expand(@lines_with_tabs);
@lines_with_tabs = unexpand(@lines_without_tabs);
π DESCRIPTION π
So Text::Tabs does most of what the unix utilities expand(1) and unexpand(1) do. no cap.
- give it a line with tabs in it and
expandswaps those tabs out for the right amount of spaces β¨ - give it a line with or without tabs in it and
unexpandadds tabs back whenever it can save bytes by doing so, exactly like theunexpand -acommand π
but here's the glow-up: unlike those old unix utilities, this module correctly accounts for any Unicode combining characters (diacriticals and friends) that might show up in each line, and it does that for both expansion and unexpansion. these are overstrike characters β they don't increment the logical position. π§
bestie pls make sure you have the appropriate Unicode settings enabled before you come for me πΈ
π EXPORTS π
the following are exported, periodt:
expandunexpand$tabstop
π $tabstop π
The $tabstop variable controls how many column positions apart each tabstop is. The default is 8.
okay this part is important so listen up π: please note that local($tabstop) doesn't do the right thing, and if you want to use local to override $tabstop, you need to use local($Text::Tabs::tabstop). like, that's the whole thing. iykyk.
β EXAMPLE β
#!perl
# unexpand -a
use Text::Tabs;
while (<>) {
print unexpand $_;
}
Instead of the shell's expand command, use:
perl -MText::Tabs -n -e 'print expand $_'
Instead of the shell's unexpand -a command, use:
perl -MText::Tabs -n -e 'print unexpand $_'
π BUGS π
ngl, Text::Tabs handles only tabs ("\t") and combining characters (/\pM/). It doesn't count backwards for backspaces ("\t"), omit other non-printing control characters (/\pC/), or otherwise deal with any other zero-, half-, and full-width characters. π that's just the vibe it's on.
π LICENSE π
Copyright (C) 1996-2002,2005,2006 David Muir Sharnoff. Copyright (C) 2005 Aristotle Pagaltzis Copyright (C) 2012-2013 Google, Inc.
This module may be modified, used, copied, and redistributed at your own risk. π
And although the preceding license allows it, please do not publicly redistribute modified versions of this code with the nameText::Tabsunless it passes the unmodifiedText::Tabstest suite. π«Ά
that's the whole page bestie, you ate it πβ¨ β brought to you by perl v5.44.0, dated 2026-10-17, and living its best life as Text::Tabs(3perl). mwah π
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms