That works of course, but Devel::REPL is much more convenient: (1) you don't have to end your statements with backslashes -- you can paste whole blocks as is, (2) you immediately see what your statement evaluates to, for example typing "42" in Perl debugger simply begins another prompt while typing it in a true REPL returns the value that your statement evaluates to (i.e. "42") -- which is not a big deal with simple statements but gets interesting once you start evaluating regular expressions, for example, (3) Devel::REPL remembers what you typed (or at least it works the same way as your system shell), (4) it is really easy to work out complicated things in Devel::REPL -- see for example this case of currying a function:
$ my $x = sub { my $x = shift; return sub { $x . shift } }
$CODE1 = sub { # this is what is returned by Devel::REPL
package Devel::REPL::Plugin::Packages::DefaultScratchpad;
use warnings;
use strict 'refs';
my $x = shift @_;
return sub {
$x . shift(@_);
}
;
};
$ $x->('hello ')->('world');
hello world