=pod This program reads text from "stdin" and writes to "stdout" on exit. It can be used to do in-place editing of a file by executing with perl -i.bak If you exit via 'OK' or 'Cancel', the process exit code will be 0 or 1, respectively. If you exit with 'Cancel' and are NOT running with perl -i, the text will not be printed to "stdout". Examples: % foo | perl stream_editor_tk | bar # foo produces text; # stream_editor_tk is this program; # bar consumes text. % perl -i.bak stream_editor_tk some_doc.txt # edit a file in place. =cut use Tk; use strict; use warnings; my $orig = $_ = do { local $/; <> }; my $code = 1; my $mw = new MainWindow( -title => 'Edit' ); my $fr = $mw->Frame( -border => 2, -relief => 'raised' )->pack( -side => 'bottom', -fill => 'both', ); my $text = $mw->Scrolled( 'Text', -wrap => 'none' )->pack( -side => 'bottom', -fill => 'both', -expand => 1 ); $fr->Button( -text => 'Reset', -command => sub { $text->delete( '1.0', 'end' ); $text->insert( end => $_ ) } )->place( -relx => 0.25, -anchor => 'n', ); my $ok = $fr->Button( -text => 'OK', -command => sub { print $text->get( '1.0', 'end' ); $code = 0; $mw->destroy } )->place( -relx => 0.5, -anchor => 'n', ); $fr->Button( -text => 'Cancel', -command => sub { defined $^I and print $orig; $mw->destroy } )->place( -relx => 0.75, -anchor => 'n', ); $mw->after( 100, sub { $fr->configure( -height => $ok->height + 5 ); } ); $text->insert( end => $_ ); MainLoop; exit $code;