I have a longer script 'pash', that uses Term::ReadLine for history support. The only thing about 'pash' is that you hit enter twice - this allows multi-line entries.
#!/usr/bin/perl
#
# pashn - simple perl shell with Readline support
# $Id: pashn,v 1.1 2003/11/05 12:57:48 banjo Exp $
#
# copyright 2003 Billy Naylor
# banjo@actrix.co.nz
#
# This is GPL software...
# See the GNU General Public Licence
# http://www.fsf.org/licenses/gpl.txt
#
use Term::ReadLine;
my $help = <<EOH;
pashn is a simple perl shell, it allows you to
type in raw perl, fragments and subs.
You can also run shell commands by appending
the command with a bang!
However 'my' and 'local' will only work inside
a single statement, and so multiline code can be
entered you must hit return twice.
But in return, Term::ReadLine is here to give
us history and non-destructive backspaces, and
multiline editing, and bash or vi keybindings,
and of course you can easily 'use' oodles of
CPAN modules, ?
EOH
my $terminal = Term::ReadLine->new('PASH');
$terminal->ornaments(0);
$terminal->MinLine(undef);
$| = 1;
my $prompt = "pashn; ";
while () {
my $editbuffer = $terminal->readline( $prompt );
while () {
my $b = $terminal->readline('');
last unless $b;
$editbuffer .= "$b\n";
}
chomp $editbuffer;
$terminal->addhistory($editbuffer);
if ($editbuffer =~ s/^\s*\!//) {
print qx|$editbuffer|;
next;
}
eval ("$editbuffer");
print $@ if $@;
print "\n";
next;
}
sub help { print $help }
sub quit { exit 0 }
# thankyuoverymuchGoodnight
exit 0;
|