tcf22 has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to write a shell like interface to manage some files, but I'm running into a problem when I'm trying to get fancy and use command completion. The problem is that using read(or sysread) you must press "Enter" before it starts reading from the buffer. I need it to run through the loop each time a character is typed. I tried using something like this
my ($buffer, $command); while(read(STDIN, $buffer, 1)){ #print "Read Character $buffer\n"; if($buffer eq "\t"){ ##Do command completion stuff last; }else{ $command .= $buffer; } } if($command eq "this"){ #Stuff }elsif($command eq "this"){ #More Stuff }...


Also if I can get this working, and I display the correct command, is there a way to put the command into STDIN, so that when they press "Enter" it will execute that command.

Replies are listed 'Best First'.
Re: Flushing STDIN after each character
by ChrisS (Monk) on Aug 15, 2003 at 15:22 UTC
Re: Flushing STDIN after each character
by wirrwarr (Monk) on Aug 15, 2003 at 15:45 UTC
    Term::ReadLine::Gnu seems to support tab completion. Might be worth a look, if you can get it to run on your system
    (*nix boxes should work without problem, not sure about windows).

      Term::ReadLine::Perl is a Pure Perl implementation of readline that should work on any system.

      bbfu
      Black flowers blossom
      Fearless on my breath