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.
| [reply] |
|
|
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.
| [reply] |
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.
| [reply] [d/l] |
Re: backspace works in shell, but not in Perl?
by DaWolf (Curate) on Feb 28, 2004 at 18:12 UTC
|
| [reply] |
|
|
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);
}
| [reply] [d/l] |
|
|
| [reply] [d/l] |
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.
| [reply] [d/l] [select] |