Perl: console / command-line tool for interactive code evaluation and testing Perl: console / command-line tool for interactive code evaluation and testing shell shell

Perl: console / command-line tool for interactive code evaluation and testing


   perl -d -e 1

Is perfectly suitable, I've been using it for years and years. But if you just can't,then you can check out Devel::REPL


If your problem with perl -d -e 1 is that it lacks command line history, then you should install Term::ReadLine::Perl which the debugger will use when installed.


Even though this question has plenty of answers, I'll add my two cents on the topic. My approach to the problem is easy if you are a ViM user, but I guess it can be done from other editors as well:

  1. Open your ViM, and type your code. You don't need to save it on any file.

  2. :w !perl for evaluation (:w !COMMAND pipes the buffer to the process obtained by running COMMAND. In this case the mighty perl interpreter!)

  3. Take a look at the output

This approach is good for any interpreted language, not just for Perl.

In the case of Perl it is extremely convenient when you are writing your own modules, since in my experience the perl interpreter will refuse to reload a module (even when loading was attempted and failed). On the minus side, you will loose all your context every time, so if you are doing some heavy or slow operation, you need to save some intermediate results (whilst the perl console approach preserves the previously computed data).

If you just need the evaluation of an expression - which is the other use case for a perl console program - another good alternative is seeing the evaluation out of a perl -e command. It's fast to launch, but you have to deal with escaping (for this thing the $'...' syntax of Bash does the job pretty well.