03-26-2004 05:32 AM
from the user in the form of:
which works just fine, except that it the user
types a backspace because he misspelled a word,
the backspace characters show up in the complete text! If what is being entered is a file name, the file can not be found! How can I get perl to read the data already collapsed?
Or, how can I collapse it before saving it?
Thanks for your assistance,
Solved! Go to Solution.
03-26-2004 05:57 AM
$indata =~ s/^\b+//;
# Step 2. remove all backspace
1 while $indata =~ s/.\b//;
FWIW $indata =~ s/.\b//g; would not work, because that would fail to remove
Enjoy, Have FUN! H.Merijn
03-26-2004 06:18 AM
When I enter: myfle
I get nothing (null?) after those commands.
What I want to get is: myfile
How can I get that? Even as I read your code, I am not sure I would have got what I wanted anyway. It looks like I'd get: myfleile, which isn't what I need.
03-26-2004 06:48 AM
lt09:/tmp 107 > perl -de 1
Loading DB routines from perl5db.pl version 1.23
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
DB<1> $indata = "myfle^H^Hile"
DB<2> x $indata
DB<3> $indata =~ s/^\b+//
DB<4> x $indata
DB<5> 1 while $indata =~ s/.\b//
DB<6> x $indata
Now I see that I erroneously misused \b as backspace, which it is not in a regex.
chomp ($indata = "myfle\b\bile"); # Here it *is* a backspace
$indata =~ s/^\cH+//; # Ctrl-H is backspace
1 while $indata =~ s/.[\b]//; # \b also is backspace inside character class
DB<7> chomp ($indata = "myfle\b\bile"); # Here it *is* a backspace
DB<8> x $indata
DB<9> $indata =~ s/^\cH+//; # Ctrl-H is backspace
DB<10> x $indata
DB<11> 1 while $indata =~ s/.[\b]//; # \b also is backspace inside character class
DB<12> x $indata
Enjoy, Have FUN! H.Merijn [ 0 points for the first answer. I feel ashamed! ]
03-26-2004 06:59 AM
You get 2 points for the first try. I don't anyone should get 0 points if they respond to a help request :-)