NB: These pages were mostly written in 2001 or so. The résumé dates are accurate but the code is aged and unlike whiskey, 8 year-old code doesn't usually taste better. For a look at my current skills and to see my CPAN modules, sample code, and code discussions, please see these pages instead: Perl resources and sample code and PangyreSoft.
Fake Perl shell
Social links
View Ashley Pond V's profile on LinkedIn
Miscellaneous

Other pages

Description

Many programmers have worked many hours on building a pure Perl shell. This little recipe allows you to execute perl code interactively and acts like the shell. It would need some Term::ReadKey and other good sauce to really be convincing but this is pretty good in a pretty small space.

It’s tremendously useful for testing code interactively in a single terminal window.

This recipe is adapted from one by Dr. Tim Maher who administers the Seattle Perl Users Group (SPUG). The meat of the script is really only 3 or 4 lines and note the “-n” switch on the shebang line.

Code
Usage
jinx[203]>perl-shell

        Type exit when you are ready to stop.

jinx@perl-shell[1]>
jinx@perl-shell[1]>print 22/7
3.14285714285714
jinx@perl-shell[2]>sub big { $text = shift; return `banner $text` }

jinx@perl-shell[3]>monkey

jinx@perl-shell[4]>print bif('monkey') 
Undefined subroutine &main::bif called at (eval 2) line 1, <> line 2.

jinx@perl-shell[5]>print big('monkey')

 #    #   ####   #    #  #    #  ######   #   #
 ##  ##  #    #  ##   #  #   #   #         # #
 # ## #  #    #  # #  #  ####    #####      #
 #    #  #    #  #  # #  #  #    #          #
 #    #  #    #  #   ##  #   #   #          #
 #    #   ####   #    #  #    #  ######     #


jinx@perl-shell[6]>exit

                Bye!

jinx[204]>

Discussion

You may ask, “Why on earth go to the trouble? The debugger does the same thing as easy as perl -de 42.”

Well, you got me. The debugger does much more too. Larry Wall, the creator of Perl who wrote the debugger, however, admits he almost never uses it. Some programmers swear by it but it’s not easy or fun to use. Unless you’re trying to track down memory leaks, namespace problems or other killer bugs, the perl-shell above is a more familiar approach with easier error reporting.

Search these pages via Google
Text, original code, fonts, and graphics ©1990-2009 Ashley Pond V.