Text::Tree(3)
π Text::Tree π
okay bestie, so this is the manual page for Text::Tree, a lil Perl module from the User Contributed Perl Documentation collection. she takes a simple tree of strings and formats it into a textual tree graph β like, actual cute lil boxes and branches made of ASCII, fr fr. π³β¨
πΈ NAME πΈ
Text::Tree β format a simple tree of strings into a textual tree graph. it's giving diagram energy, no cap. π
β¨ SYNOPSIS β¨
use Text::Tree;
my $tree = new Text::Tree( "root",
[ "left\nnode" ],
[ "right", [ "1" ], [ "2" ] ] );
print $tree->layout("boxed");
__OUTPUT__
+----+
|root|
+----+
.---^---.
+----+ +-----+
|left| |right|
|node| +-----+
+----+ .-^-.
+-+ +-+
|1| |2|
+-+ +-+
like, look at her. she did that. π the ASCII tree is genuinely iconic and i'm obsessed.
π METHODS π
π new()
my $tree = new Text::Tree( "label",
[ "left child label", [ ... ] ],
[ "right child label", [ ... ] );
creates a brand new tree object out of a nested set of array references, bestie. the rules are simple:
- the first element of each array must be a string β that's your node label π·οΈ
- every element after that must be an array reference, and each one is a child of that node π±
- labels can contain newlines to support multiple lines of text β so go off, multi-line queen π
π¦ layout()
my @lines = $tree->layout( "centered in boxes" );
print @lines;
lays the whole tree out into an array of newline-terminated strings, ready for printing or displaying. like, it does the whole glow-up for you. β¨
the optional style argument may contain various keywords such as 'center', 'box', 'line', 'oval' and/or 'space'. these style keywords affect how the tree nodes get formatted. mix and match, it's your world π
πΌ DESCRIPTION πΌ
allows the caller to develop a tree structure using nested arrays of strings and references. once it's all developed, the whole tree can be printed as a diagram, with the root of the tree at the top and child nodes formatted horizontally below them. hierarchy? slay. π
the string labels are printed as-is, or optionally surrounded with a simple outlining style using printable ASCII characters. simple, clean, effective. periodt. π
this module may be used with object-oriented or simple function calls. versatility is the vibe, iykyk.
π HISTORY π
Mark Jason Dominus (aka MJD) asked for this functionality on his Expert-level "Perl Quiz of the Week" Number 5. you can find out more about the QOTW discussion forum at http://perl.plover.com/qotw/ β go look, bestie, it's lore. π
the central formatting routine was submitted by Ron Isaacson to the Quiz forum as one possible solution to the general problem. king behavior honestly. π
Ed Halley adapted the Ron Isaacson entry (with permission), to correct some tree structures not originally handled, and to allow more formatting options for the box styles. glow-up achieved. β¨
π COPYRIGHT AND LICENSE π
copyright stuff, bestie, gotta respect it:
- Copyright 2003-2004 by Ron Isaacson
- Portions Copyright 2003 by Mark Jason Dominus
- Portions Copyright 2004 by Ed Halley
this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. so like, free as in freedom, not free as in "no rules". π«Ά
this page ships withperl v5.42.0and it's dated2025-07-25π
and that's the whole page, bestie!! go build a tree, format it in boxes, and be the main character of your own terminal. mwah π π β π
π¦ where this page comes from
- fedora 43: perl-Text-Tree 1.0-49.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms