#!/usr/local/bin/perl -w use strict; BEGIN { # from Camel book 2nd ed. p.474 use POSIX qw(:termios_h); my ($term, $oterm, $echo, $noecho, $fd_stdin); $fd_stdin = fileno(STDIN); $term = POSIX::Termios->new(); $term->getattr($fd_stdin); $oterm = $term->getlflag(); $echo = ECHO | ECHOK | ICANON; $noecho = $oterm & ~$echo; sub cbreak { $term->setlflag($noecho); $term->setcc(VTIME, 1); $term->setattr($fd_stdin, TCSANOW); } sub cooked { $term->setlflag($oterm); $term->setcc(VTIME, 0); $term->setattr($fd_stdin, TCSANOW); } } END { cooked(); } cbreak(); while (1) { my ($rin, $rout, $nfound); $rin = ''; vec($rin, fileno(STDIN), 1) = 1; if ($nfound = select($rout=$rin, undef, undef, 0.001)) { my ($key); sysread(STDIN, $key, 1); if ($key eq 'j') { print "It was j!\n"; } elsif ($key eq 'q') { print "I'm melting!\n"; exit; } } }