#!/usr/bin/perl -w
######################################################################
# text.pl
######################################################################
# Perl Power! - Michael Schilli 1998
######################################################################

use Tk;

my $top = MainWindow->new();

my $frame = $top->Frame();

my $text = $frame->Text(-wrap => 'none');

                               # define scrollbars
my $yscrollbar = $frame->Scrollbar(-command => 
                                   [yview => $text]);
my $xscrollbar = $top->Scrollbar(-orient => 'horizontal', 
                                 -command => [xview => $text]);

                               # ... and set them
$text->configure(-yscrollcommand => [set => $yscrollbar]);
$text->configure(-xscrollcommand => [set => $xscrollbar]);

                               # pack all
$yscrollbar->pack(-side => 'right', -fill => 'y');
$xscrollbar->pack(-side => 'bottom', -fill => 'x');

$frame->pack(-expand => 'yes', -fill => 'both');
$text->pack(-expand => 'yes', -fill => 'both', 
            -side => 'left');

foreach $row (1..30) {         # insert 30 lines
    $text->insert("end", "Line $row\n");
}

# delete third line
$text->delete("3.0", "4.0");

# insert new third line
$text->insert("3.0", "Text of the new third line\n");

# swap fourth and fifth line

$line4 = $text->get("4.0", "5.0");          # get line 4
$line5 = $text->get("5.0", "6.0");          # get line 5
$text->delete("4.0", "6.0");                # delete lines 4 and 5
$textstring = $text->insert("4.0", $line5); # insert new line 4
$textstring = $text->insert("5.0", $line4); # insert new line 5

MainLoop;

