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.

#!/usr/bin/perl -wn

# the -n switch gives us a loop around the script. the BEGIN block is
# only executed once. it sets up our prompt and turns off the signals
# that could interrupt the script

BEGIN {
# turn off control keys
    $SIG{$_} = 'IGNORE' for keys %SIG;   
# let the user know how to get off this crazy thing.
    print "\n\tType\e[1m exit\e[0m when you are ready to stop.\n";

    $history = 1;
    sub prompt {
        print "\n", $ENV{USER}, '@perl-shell[', $history++, ']>';
    }
    prompt;
}
# the body is executed over and over (each time <> is given). all we
# do is eval the body, and voila, perl-shell behavior

eval;
$@ and warn $@;  # give perl errors back to the user

prompt;                # print a fresh prompt with updated history

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.