in reply to Re^2: Regex arrow key problem
in thread Regex arrow key problem

This should look suspiciously similar to what BrowserUK has shown in Re: Regex arrow key problem. If you intend to capture left and right arrows, you need to handle multi-character inputs, as BrowserUK has in Re^5: Regex arrow key problem. It might be worth asking if this is an XY Problem - what is your end goal?

Replies are listed 'Best First'.
Re^4: Regex arrow key problem
by austin43 (Acolyte) on Dec 01, 2010 at 20:40 UTC
    My end goal in this situation is just to be able to use arrow keys for browsing through different areas of a script. Whenever an arrow key is pressed I want it to run a new subroutine as specified. Currently I have it matching "q" for previous subroutine and "w" for next subroutine. I figured this is not as intuitive as <- ->. I am very new to perl, and it is essentially my first programming language. I will try to figure out a way to implement multiple input capturing. The entire script, with its 5 or so modules, is about 8000-9000 lines, so it will be interesting to figure out how to do that. Gosh I wish there was an easier way to do this.
      My end goal in this situation is just to be able to use arrow keys for browsing through different areas of a script. Whenever an arrow key is pressed I want it to run a new subroutine as specified.
      That is not your end goal - that is still a method for accomplishing it. What task does your script accomplish? Think PHB big picture. Or are you saying you are trying to build a text editor? It sounds like you are trying to create a command line interface (CLI) for existing libraries.
      I am very new to perl, and it is essentially my first programming language.
      The language is Perl, the program is perl, just so you know. For someone with not a lot of background, you have selected a very hairy task to cut your teeth on. I would suggest sticking with the simple inputs ('q', 'w') unless there is a strong reason for changing. I have been doing this a while, and I would have pause before picking up the task you've laid out.
      The entire script, with its 5 or so modules, is about 8000-9000 lines
      Are you modifying a script that someone else wrote? Wrapping other people's code?

      I note that in your original code, you have goto. I have never used a goto in a Perl script - the more natural solution is (usually) a dispatch table.

        Nope I have written it from the ground up. Sorry, I wasn't entirely clear on what you meant by end goal. It is a mix of perl and shell script, and it is built to automate tedious security patches and other fixes on CentOS Linux machines (for my job). I may look in to dispatch tables in the future, but for now goto does what I need it to. Thanks for all your help.