in reply to Regex arrow key problem

[ Please place blocks of computer text (e.g. code, data and output) in <c>...</c> tags. ]

The first step would be to find out what ReadKey is returning. You could use

use Data::Dumper; { local $Data::Dumper::Useqq = 1; print(STDERR Dumper($input)); }

Replies are listed 'Best First'.
Re^2: Regex arrow key problem
by austin43 (Acolyte) on Dec 01, 2010 at 19:22 UTC
    The left arrow key is returning "\e[D\n", and the right arrow key is returning "\e[C\n". How do I match this?
      if ($input eq "\e[D\n")
      and
      if ($input eq "\e[C\n")

      You obviously removed the lc to get those values. Be careful about re-adding lc. Only lowercase $input after checking for these special keys.

        I tried your code, with and without lc, and it didn't work still.
Re^2: Regex arrow key problem
by austin43 (Acolyte) on Dec 01, 2010 at 21:25 UTC
    I tried implementing it within my code instead of in its own script and it returns $VAR1 = undef;. EDIT: I accidentally put it above ReadMode(0); and that's why it returned undef. Now I put it below the $input string and it returns
    RIGHT ARROW
    $VAR1 = "\e"; $VAR1 = "["; $VAR1 = "c";
    LEFT ARROW
    $VAR1 = "\e"; $VAR1 = "["; $VAR1 = "d";
      So only one of the three characters is returned at a time. BrowserUK has already posted how to handle that.