一个命令行交互脚本

按q键退出,否则显示用户输入。

#! /usr/local/bin/perl5

use strict;
use warnings;

sub test {
    while (1) {
        # display the prompt
        print "sditest> ";

        # Get input form STDIN, this is short for my $get = <STDIN>
        chomp (my $get = <>);

        # Quit when user pressed 'q', otherwise print what ever input
        if ($get eq 'q') { # How to determine user pressed Esc here?
            exit;
        }
        else {
            print $get, "\n";
        }
    }
}

test();

 

==

posted on 2012-04-12 09:59  perlman  阅读(632)  评论(0编辑  收藏  举报

导航