Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!casbah.acns.nwu.edu!nucsrl!tellab5!laidbak!obdient!syzzle!system From: system@syzzle.chi.il.us (awol) Newsgroups: comp.lang.perl Subject: Re: perl equivalent of "pg" or "more"? Message-ID: Date: 26 May 91 00:24:01 GMT References: <1991May25.042644.2554@jpl-devvax.jpl.nasa.gov> Organization: System Solutions - Wheaton, Il. Lines: 40 lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) writes: > system@syzzle.chi.il (awol) writes: > > : Definately not a perl guru......yet, but I did do this simple version. > : What I would like to know though, is how can I get just one key press > : (without waiting for ENTER)? I would like to do something like this, and > : then after one key is pressed backup and erase the prompt. I posted this > : question a short while back, but haven't seen any responses. > : > : #!/usr/bin/perl > : # > : $lines = 0; > : while (<>) { > : $lines++; > : print; > : next unless $lines == 23; > : $lines = 0; > : print "==> "; > : $answer = getc; > : last if $answer eq "q"; > : } > > Depends on your OS, but you can usually use one of `stty cbreak` > or `stty -icanon`. You might also get better results using > sysread(STDIN,$answer,1) rather than getc. To erase the line, > print "\r" and whatever else is appropriate. You may need to set $| > to make sure the string gets flushed from the buffer. > > Larry I am using MS-DOS. I had tried using read before, and did try sysread, but everything requires pressing return. Then I can't just back up to erase the prompt because I'm already on the next line. If it is not possible to do this (get one keypress) on the dos version, it would be a nice feature to add. Similiar to the Turbo-C getch function. +------------------------+-----------------------------------+ | Al Oomens (awol) | Inside every LARGE program is | | awol@syzzle.chi.il.us | a small program trying to get out.| +------------------------+-----------------------------------+