In: , ,
On: 2004 / 03 / 12
Shorter URL for this post: http://ozh.in/q

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" }

Shorter URL

Want to share or tweet this post? Please use this short URL: http://ozh.in/q

Metastuff

This entry "Fake perl shell" was posted on 12/03/2004 at 7:28 pm and is tagged with , ,
Watch this discussion : Comments RSS 2.0.

No Comment yet

  1. TomBoss says:

    FirstPost
    (au cas ou)

  2. Ozh says:

    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

  3. ashley says:

    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.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar and sign for a free account
Spam: Various spam plugins may be activated. I'll put pins in a Voodoo doll if you spam me.

Read more ?

 ps monitor »