#!/usr/local/bin/perl -ws use vars qw( $n ) ; $|= 1 ; $num = 0 ; print "\nWelcome to quote_serve\nType help for help\n\n" ; prompt() ; %disp_table = ( 'help' => \&help, 'pid' => \&pid, 'yow' => \&yow, 'insult' => \&insult, ) ; while( <> ) { tr/\r\n//d ; if ( /^q/ ) { print "Quitting\n" ; #sleep 1 ; # print STDERR "Quitting 2\n" ; # exit ; last ; } if ( /^$/ ) { $cmd = $prev_cmd or next ; } elsif ( /^(\w+)/ ) { $cmd = $1 ; } elsif ( /^\s+$/ ) { next ; } else { print STDERR "No command found\n" ; next ; } $func = $disp_table{ $cmd } ; unless( $func ) { print STDERR "Unknown command '$cmd'\n" ; next ; } $resp = $func->( $_ ) ; if ( $n ) { $num++ ; print "\n$num: $resp\n" ; } else { print "\n$resp\n" ; } $prev_cmd = $cmd ; } continue { prompt() ; } sub prompt { print "\nquote_serve: " } sub help { return <