From: Wybo Dekker Date: 2005-06-17T07:41:22+09:00 Subject: Re: stubborn program using readline On Thu, 16 Jun 2005, Logan Capaldo wrote: > Theory: readline reads from STDIN correct? using rltest < rltest means > that STDIN gets EOF, which means STDIN is closed which means readlien > can't read anything from it. No, readline should not necessarily read from STDIN. It can read from the console, /dev/tty or so. > I don't think you can have your cake and > eat it too in this case. If you want the interactive prompt your going > to have pass the file name on the command line instead of using IO > redirection. I'm a bit confused as to the purpose of this. What I want is a program that reads data from either a file or STDIN and then lets the user run various commands on those data. To be more specific, it's a program (vpp, http://www.servalys.nl/scripts/vpp) that I have written in Perl and it reads a PDF (or PostScript) file, displays it, and after this offers the user a command prompt where she can choose to print some pages, or all pages, in various formats (booklet, one-sided, two-sided), either to a printer or to an other PDF file. PDF (or PostScript) files can be offered to it: vpp some_pdf_or_postscript_file or piped to it: vpp ) { push(@x,$_); } use Term::ReadLine; my $t=new Term::ReadLine 'vpp'; while ( (my $n = $t->readline("type line number (0 to stop): ")) > 0) { if ( $n > @x) { print "no such line\n"; } else { print "line $n: $x[$n-1]"; } } and then run it like so: $ showline < showline type line number (0 to stop): 1 line 1: #!/usr/bin/perl -w type line number (0 to stop): 3 line 3: # showline - read lines from stdin, type line number (0 to stop): 20 line 20: } type line number (0 to stop): 21 no such line type line number (0 to stop): 0 $ -- Wybo