Skip to Content
Programming Perl, 3rd Edition
book

Programming Perl, 3rd Edition

by Larry Wall, Tom Christiansen, Jon Orwant
July 2000
Intermediate to advanced
1104 pages
35h 1m
English
O'Reilly Media, Inc.
Content preview from Programming Perl, 3rd Edition

Text::Wrap

use Text::Wrap;  # Imports wrap().

@lines = (<<"EO_G&S" =~ /\S.*\S/g);

    This particularly rapid,
    unintelligible
    patter isn't generally
    heard,
    and if
    it is, it
    doesn't matter.

EO_G&S

$Text::Wrap::columns = 50;
print wrap(" " x 8, " " x 3, @lines), "\n";

This prints:

           This particularly rapid, unintelligible
      patter isn't generally heard, and if it is, it
      doesn't matter.

The Text::Wrap module implements a simple paragraph formatter. Its wrap function formats a single paragraph at a time by breaking lines at word boundaries. The first argument is the prefix prepended to the first line returned. The second argument is the prefix string used for all lines save the first. All remaining arguments are joined together using a newline as the separator and returned as one reformatted paragraph string. You'll have to figure out your terminal's width yourself, or at least specify what you want in $Text::Wrap::columns. Although one could use the TIOCGWINSZ ioctl call to figure out the number of columns, it would be easier for those not used to C programming to install the CPAN module Term::ReadKey and use that module's GetTerminalSize routine.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Perl, 4th Edition

Programming Perl, 4th Edition

Tom Christiansen, brian d foy, Larry Wall, Jon Orwant
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
Programming the Perl DBI

Programming the Perl DBI

Tim Bunce, Alligator Descartes

Publisher Resources

ISBN: 0596000278Supplemental ContentErrata