Why I wrote Perl Console (or why I don’t use perl -e 1 -d)
Since Perl Console has been released, I received a couple of mails from random people asking me what were the differences between my console and the internal Perl debugger (that is accessible with `perl -e 1 -d`).
Here is a common answer to that question (so I won’t have to write again and again the same mail).
Q: What are the specials features in your solution that are not in ‘perl -e 1 -d’ ?
A: First of all, it’s clearly more user-friendly as it provides completion with variable names and module’s symbols and saves your history in ~/.perlconsole_history. You have all the Term::Readline goodness with the console, which is a major improvement when you use the console all day for testing your code, writing Perl modules or even writing unit-tests.
Second (the most important part to me), Perl Console is a Read-Eval-Print-Loop. “perl -e 1 -d’ is not : it does not prints out your results if you don’t tell it to.
Here is a short example that speaks by itself:
$ perl -e 1 -d [..] main::(-e:1): 1 DB<1> 1 + 1 DB<2> ^D $ perlconsole Perl Console 0.3+svn Perl> 1+1 2 Perl>
Having always the result of your expression without needing to ask for it is, to me, a major improvement. And that’s what a REPL program is supposed to do.
One major difference between those two environments is about the namespace. In Perl Console all your code is evaluated under the strict mode. Meaning all your commands have to be “use strict” valid. You cannot use $foo if $foo wasn’t declared before with a “my”. In Perl Console, everything declared with my is saved in the console’s namespace. That’s not the case with the debugger which has one namespace by line. Let me prove this:
DB<1> my $foo = 42 DB<2> print "foo: $foo" foo: DB<3> $bar = 84 DB<4> print "bar: $bar" bar: 84
As you can see, in the debugger, variables declared with “my” are not in the scope of other commands. In Perl Console, they are (and you cannot use undeclared variables as you are in scritct mode, which is good) :
Perl> my $foo = 42 42 Perl> $foo 42 Perl> $bar = 84 [!] compilation error: Global symbol “$bar” requires explicit package name at (eval 9) line 4.
You can also load any module you like within the console and each of these modules will be refreshed transparently if they changed on disk. That’s more than useful when you write a module and test it with the console (you don’t have to quit the console to get the changes applied).
Moreover, Perl Console provides different output modes, you can choose the one you like between Data::Dumper, YAML, Data::Dump and Data::Dump::Streamer (in version 0.3).
Let’s take a look at some output modes:
Perl> :set output=scalar
Perl> my $hash = {foo => 1, bar => 2, baz => 4}
HASH(0x83a52a0)
Perl> :set output=dumper
Perl> $hash
$VAR1 = {
'bar' => 2,
'baz' => 4,
'foo' => 1
};
Perl> :set output=yaml
Perl> $hash
---
bar: 2
baz: 4
foo: 1
Perl>
The console can also source a startup script if you like to load a module for instance and define a couple of variables you like to have in your test sessions : perlconsole –rcfile ~/.perlconsole-myproject for instance.
To conclude, it’s far more user-friendly and powerful than the perl internal debugger and is designed to be your all-day companion for testing strict code.

