The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/local/bin/perl -w

require 5.001;
use IO::Handle;
use Tk;

{package WrapMain;
 sub new
 {
  my $class = shift;
  my $mw = $::mw;
  $mw->configure(@_) if @_;
  @MainWindow::ISA = 'Tk::MainWindow';
  return $mw;
 }
}

@MainWindow::ISA = 'WrapMain';

$mw = $top = Tk::MainWindow->new;
$mw->title('tkpsh');
$top->iconname('tkpsh');

if (@ARGV)
 {
  local @Tk::EXPORT;
  do $ARGV[0];
 }

autoflush STDOUT 1;

$mw->fileevent(STDIN,'readable',\&doline);

sub doline
{
 my $line = <STDIN>;
 if (!defined $line)
  {
   $mw->fileevent(STDIN,'readable','');
   $mw->destroy;
  }
 else
  {
   if ($line =~ /^p\s(.*)$/)
    {
     $line = "print $1, \"!\\n\";";
    }
   eval $line;
   print "$@\n" if $@;
   print "tkpsh> ";
  }
}

print "tkpsh> ";
MainLoop;
print "\n";