Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: perl equivalent of "pg" or "more"? Message-ID: <1991May25.042644.2554@jpl-devvax.jpl.nasa.gov> Date: 25 May 91 04:26:44 GMT References: <1991May7.092222.625@arizona.edu> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 35 In article system@syzzle.chi.il.us (awol) writes: : jew@rt.sunquest.com (/87336) writes: : : > This is a question for you perl gurus... How hard is it to duplicate : > the functionality of "pg" or "more" in perl. Mainly, pagination and : > searching for strings both forward and backwards. Seems like it might : > be pretty easy and related to the previous question of how to print : > the last N pages of a file. Any takers? Thanks in advance. : : 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