Fake perl shell

This script emulates a (really ugly) perl shell within your bash (or wathever) session. I like it to quickly test a few regexps or a function.

  1. #!/usr/bin/perl -wn
  2.  
  3. # the -n switch gives us a loop around the script. the BEGIN block is
  4. # only executed once. it sets up our prompt and turns off the signals
  5. # that could interrupt the script
  6.  
  7. BEGIN {
  8. # turn off control keys
  9.     $SIG{$_} = 'IGNORE' for keys %SIG;  
  10. # let the user know how to get off this crazy thing.
  11.     print "\n\tType\e[1m exit\e[0m when you are ready to stop.\n";
  12.  
  13.     $history = 1;
  14.     sub prompt {
  15.         print "\n", $ENV{USER}, '@perl-shell[', $history++, ']>';
  16.     }
  17.     prompt;
  18. }
  19. # the body is executed over and over (each time <> is given). all we
  20. # do is eval the body, and voila, perl-shell behavior
  21.  
  22. eval;
  23. $@ and warn $@;  # give perl errors back to the user
  24.  
  25. prompt;                # print a fresh prompt with updated history
  26.  
  27. END { print "\n\t\tBye!\n\n" }

0 comments

  1. TomBoss

    FirstPost
    (au cas ou)

  2. ashley

    and the source of the code: http://sedition.com/perl/perl-shell.html.

  3. Ozh

    Ho nice, I got it via a friend on IRC but couldnt tell where it was from. Are you the author of this script ? If so, good job, it helped me a few times

  4. ashley

    hey, there, Ozh. back after awhile. it's sort of mine, i got the original idea/skeleton from tim maher who was running the seattle perl users group.