How can I start an interactive console for Perl, similar to the irb
command for Ruby or python
for Python?
re.pl from Devel::REPL
I wrote a script I call "psh":
#! /usr/bin/perl
while (<>) {
chomp;
my $result = eval;
print "$_ = $result\n";
}
Whatever you type in, it evaluates in Perl:
> gmtime(2**30)
gmtime(2**30) = Sat Jan 10 13:37:04 2004
> $x = 'foo'
$x = 'foo' = foo
> $x =~ s/o/a/g
$x =~ s/o/a/g = 2
> $x
$x = faa
I always did:
rlwrap perl -wlne'eval;print$@if$@'
With 5.10, I've switched to:
rlwrap perl -wnE'say eval()//$@'
(rlwrap is optional)
You could look into psh here: http://gnp.github.io/psh/
It's a full on shell (you can use it in replacement of bash for example), but uses perl syntax.. so you can create methods on the fly etc.
See also Stylish REPL (for GNU Emacs) http://blog.jrock.us/articles/Stylish%20REPL.pod
You can use the perl debugger on a trivial program, like so:
perl -de1
Alternatively there's Alexis Sukrieh's Perl Console application, but I haven't used it.