in reply to Reading Single Character Input with Term::ReadKey

Try changing "^H" for "\cH" or "\x08". "^H" is just a 2 character string consisting of the characters '^' & 'H'. The other two are escape sequences that perl interprets at compile time and substitutes the approriate single control chracter, chr(8).

Indeed, it might be clearer to others and yourself later if you used

if ($key eq chr(8) ) { #Help Mode!

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Reading Single Character Input with Term::ReadKey
by Fletch (Bishop) on Apr 17, 2007 at 18:25 UTC

    Even clearer would be to hide that in a constant rather than having a bare magic number . . .

    use constant HELP_KEY => chr( 8 ); ## Control H if( HELP_KEY() eq $key ) { ## . . . }

    Alternately:

    use Readonly; Readonly my $HELP_KEY => chr( 8 ); ## Control H if( $HELP_KEY eq $key ) { ## . . . }

      I agree, but it is different advice.

      I was making suggestions on how best to define the constant. You are suggesting that he should use a symbolic constant in place of the actual constant.

      Ie. You could have made your point by suggesting

      use constant HELP_KEY => "\cH"; ## Control H

      And my point would still hold.

      As for Readonly; I "Just Say No", but that's apparently controversial :)


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.