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

I'm experiencing a strange new problem on two of my FreeBSD machines, which must have happened because I upgraded a library or something. Basically the keyboard acts like it's misconfigured when Perl is reading from standard input. The backspace key produces a ^H, and the '(' key backspaces! This does not happen in bash, or in GUI apps. It does occur with at least some other programs that read from stdin, e.g., the cat utility.

Can anyone suggest how to fix this? My only guess is that somehow one of my libraries is convinced that my keyboard layout is Norwegian or something. I've posted on comp.unix.bsd.freebsd.misc about this, but nobody had any suggestions.

TIA!

  • Comment on backspace works in shell, but not in Perl?

Replies are listed 'Best First'.
Re: backspace works in shell, but not in Perl?
by atcroft (Abbot) on Feb 28, 2004 at 17:28 UTC

    You may wish to look at something like Term::ReadLine or Term::ReadLine::Gnu. It is my understanding that those modules allow you to add such functionality to your scripts as the ability to edit a line (which sounds like the limitations of which you are encountering), or even add a command history.

      Thanks for the reply, but to clarify, it's not a limitation, it's a bug or a misconfiguration. Stuff like Term::ReadLine allows you to use fancy Emacs-like control characters for editing, but this is more fundamental. If I hit the '(' key, i.e., shift-9, it backspaces! I know it sounds insane, but that's what actually happens when I run a Perl app that reads from stdin. It's a new behavior on my two FreeBSD systems -- everything used to be fine until last month.
Re: backspace works in shell, but not in Perl? (stty)
by tye (Sage) on Feb 29, 2004 at 06:23 UTC

    Sounds like what would happen if you did 'stty erase "("' [such as in your .profile].

    Modern command shells will accept ^H for backspace even if you use such a command to say you want it otherwise.

    If this is the problem, then you can fix it (temporarily) by typing 'stty erase ^V' then your preferred backspace key (where you type that control character, not the ^ character). Note how the shell 'protecting' you from this misconfiguration makes it more difficult to correct it.

    Then search for 'stty' commands in your ~/.* files for a more permanent fix.

    I couldn't think of a way to bring this back to being Perl-related so I downvoted your question. I hope you consider that a fair trade in exchange for the information I provided. Feel free to return the favor.

    Good luck.

    - tye        

Re: backspace works in shell, but not in Perl?
by DaWolf (Curate) on Feb 28, 2004 at 18:12 UTC
    Please clarify this a little bit... If I understood correctly the problem occurs in cat too, right?

    If it does, this doesn't seem to be a Perl problem...

    Best regards,

    my ($author_nickname, $author_email) = ("DaWolf","erabbott\@terra.com.br") if ($author_name eq "Er Galvão Abbott");
      Yes, that's correct, it's not just a Perl problem, so you could argue that it's not even appropriate to post here. I'm just desperate for a way to fix it... The following C program exhibits the same behavior:

      #include <stdio.h> main() { int n; scanf("%d",&n); printf("n=%d\n",n); }
        I'm just clarifying, not suggesting that your post should be blocked. :)

        I'm waiting for the other monks to moderate your post and my suggestion was only to add a "OT" in your title, but now that is clear that this is NOT a Perl problem, I think your title should be changed.

        I only think it's important to separate things, so you can get your answer as straight and quick as possible :)

        You should search some references about FreeBSD, specially on topics like "codepages", "internationalization" and "keyboard layouts".

        Also, on Linux (not sure how this works on BSD) I'd check the environment variables (by typing env on the prompt) of the user that you use to run your code to see if everything's ok there.

        Hope that helped,

        my ($author_nickname, $author_email) = ("DaWolf","erabbott\@terra.com.br") if ($author_name eq "Er Galvão Abbott");
Re: backspace works in shell, but not in Perl?
by eXile (Priest) on Mar 21, 2004 at 15:44 UTC
    Is your problem already fixed (for this is an older node)?
    I've had the same problem, but only when I used 'rxvt', everything ok when I used a 'xterm'. I originally thought this was a perl problem because I encountered it first when using 'perl -d'. In the end (after a lot of debugging and searching) I took al look at the 'stty -a' output and guess what I found:

    'rxvt'
    ... cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>; eol2 = <undef>; erase = ^?; erase2 = (; intr = ^C; kill = ^U; lnext = ^V; min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^G; stop = ^S; susp = ^Z; time = 0; werase = ^W; ...
    'xterm'
    ... cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>; eol2 = <undef>; erase = ^H; erase2 = ^H; intr = ^C; kill = ^U; lnext = ^V; min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T; stop = ^S; susp = ^Z; time = 0; werase = ^W; ...
    Setting erase2 ('stty erase2 ^?') resolved my problem in 'rxvt'.
    Hope this helps.