In: , ,
On: 2004 / 03 / 12 Viewed: 30128 times

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.

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

Related posts

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. You can trackback this post from your own site

No Comment yet

  1. 1
    TomBoss France »
    thought, on 04/May/04 at 12:15 am # :

    FirstPost
    (au cas ou)

  2. 2
    ashley United States »
    said, on 08/Jun/04 at 7:55 pm # :

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

  3. 3
    Ozh France »
    thought, on 08/Jun/04 at 11:23 pm # :

    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. 4
    ashley United States »
    said, on 08/Sep/04 at 9:56 pm # :

    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

Comment Guidelines or Die

  • HTML: You can use these tags: <a href=""> <em> <i> <b> <strong> <blockquote>
  • Posting code: Post raw code (no <> &lt; etc) within appropriate tags : [php][/php], [css][/css], [html][/html], [js][/js], [sql][/sql], [xml][/xml], or generic [code][code]
  • Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar.
  • Spam: Various spam plugins on patrol. I'll put pins in a Voodoo doll if you spam me.
  • I will mark as Spam test comments, all comments with SEO names (ie "My Cool Online Shop" instead of "Joe") or containing forum-like signatures.

Read more ?

 ps monitor » 
Close
E-mail It