Article Sidebar jan2004.tar

Notes on Interactive Perl

One question frequently asked about Perl, which the standard FAQs barely address, is the availability of an interactive Perl shell. Many experienced Perl programmers apparently find this esoteric. However, there are several easy ways to achieve an interactive Perl shell, including:

  • Most common is to take over the built-in debugger as:
      perl -de 42
    
Not only does this give a command evaluator (unprompted), it also exposes the symbol table and variable values, permits stack backtraces, and allows for breakpoints:

  • perlsh is a more-or-less well known three-liner:

      #!/usr/bin/perl
      print ":-) ";
      while (<>) { print eval; print ( ($@ || "\n") . ":-)" ) }
    
There are slightly more elaborate forms in the standard distribution and elsewhere:

  • perl-shell is a dozen-line "pure Perl shell" authored by Ashley Pond V.
  • psh is The Perl Shell, an ongoing project hosted at SourceForge to combine "the interactive nature of a Unix shell with the power of Perl.
  • Perl Data Language "turns perl in to a free, array-oriented, numerical language similar to such commerical packages as IDL and MatLab." Its perldl is "a simple interactive shell".

A true interactive shell has been proposed for Perl 6.