Unfortunately, it returns the lines as defined in the original contents, not in the wrapped form:
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my $mw = 'MainWindow'->new;
my $t = $mw->Text(-width => 40,
-wrap => 'word')->pack;
my $b = $mw->Button(-text => 'Show',
-command => sub {
my ($last_line) = $t->index('end') =~ /(.*)\.
+/;
for my $line (1 .. $last_line) {
print "$line: ", $t->get("$line.0", "$lin
+e.end"), "\n";
}
})->pack;
$t->Contents(join ' ', split /\n/, <<'EOF');
Perl is a general-purpose programming language originally developed
for text manipulation and now used for a wide range of tasks including
system administration, web development, network programming, GUI
development, and more. The language is intended to be practical (easy
to use, efficient, complete) rather than beautiful (tiny, elegant,
minimal). Its major features are that it's easy to use, supports both
procedural and object-oriented (OO) programming, has powerful built-in
support for text processing, and has one of the world's most
impressive collections of third-party modules. Different definitions
of Perl are given in perl, perlfaq1 and no doubt other places. From
this we can determine that Perl is different things to different
people, but that lots of people think it's at least worth writing
about.
EOF
MainLoop();
Output:
1: Perl is a general-purpose programming language ...
2:
|