Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

backspacing mistakes in interactive perl script 1

Status
Not open for further replies.

womp

Technical User
Apr 6, 2001
105
0
0
US
Hello,
I have a simple perl script which Adds, Finds and Deletes people on my Unix server.
The script asks question in some areas and also verifies answers in other areas.
The problem I am have though is when the scripts ask a question like: "Put in the login name ";
and you type in the login name but "fat fingered" it then
back spaced over the mistake to retype in the correct name.
The perl script does not recognize the backspace
How can I tell my perl script what a backspace is so I won't
see ^H5?

Thank you
 
How are you reading from prompt? STDIN ?


[ponder]KrK
 
Term::ReadKey might be what you're looking for
--Paul

cigless ...
 
Sorry, the ^H needs to be a control char, not plaintext.
Or you could:
Code:
s/.\cH//g;



Trojan.
 
Trojan, that's not going to overwrite the characters that were 'fat fingered' though, is it?
--Paul
 
No, it won't overwrite them, it'll remove them (which is, I guess, what you want).

If you "fat fingered" an "X" and then typed backspace and continued, your string will contain (say) "frX^Hed" instead of "fred" (assuming that this is your problem). The regex will remove the ^H and the preceeding char leaving you with "fred" as you wanted. The "/g" modifier will make the regex repeat that operation for as many "fat fingered" mistakes as there are in the string.


Trojan.
 
TrojanWarBlade
You are correct on the difficulties I am having after your
last note. I am receiving frX^Hed when I "fat finger" a
name. Yes, I am using STDIN to read the input.

What is regex and how do I use it?

womp
 
Show me the code where you read the text in and I'll show you how to use the regex.



Trojan.
 
sub find_user {
@Find_user = ();
print "In find\n";
print "Enter a string to find, e.g. doe, or doej\n ";
$login = <STDIN>;
chomp $login;
print "$?\n";

In the print "Enter a string to find, e.g. doe, or doej\n ";
This is where, if you fat finger the login name you cannot backspace and fix it unless you cntrl-c out and start all over

womp
 
Code:
sub find_user {
        @Find_user = ();
        print "In find\n";
        print "Enter a string to find, e.g. doe, or doej\n ";
        $login = <STDIN>;
        chomp $login;
        $login =~ s/.\cH//g;
print "$?\n";

Try that.



Trojan.
 
/aside, does Ctrl-U still work on the command line?

cigless ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top