Sponsored Content
Top Forums Shell Programming and Scripting Perl script backspace not working for Unicode characters Post 302500484 by tdw on Monday 28th of February 2011 07:21:02 PM
Old 02-28-2011
Perl script backspace not working for Unicode characters

Hello,

My Perl script reads input from stdin and prints it out to stdout. After I read input I use BACKSPACE to erase characters. However BACKSPACE does not work with Unicode characters that are multi-bytes. On screen the character is erased but underneath only one byte is deleted instead of all bytes of the character, which makes remaining bytes incomplete UTF-8 characters. Here's my script:

Code:
#!/usr/bin/perl
binmode STDIN, ":encoding(utf8)";
binmode STDOUT, ":encoding(utf8)";
my $str;
while(1) {
  printf("please enter text > ");
  chomp($str = <STDIN>);
  printf("You entered: %s\n", $str);
}

I am using bash in a Putty terminal with UTF-8 encoding. Everything on Unicode works fine in shell including BACKSPACE. It is only a problem in my Perl script. Can anyone help? Thanks.

-Tom
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Backspace Not Working in Script

Hello, I've written a Perl script that prompts for asnwers to questons. At those prompts, the backspace key shows up as ^H^H. I would like the users to have the ablility to use the backspace key. I'm running bash shell and don't otherwise have this problem. Any help would be greatly... (4 Replies)
Discussion started by: Atama
4 Replies

2. Programming

How to display unicode characters / unicode string

I have a stream of characters like "\u8BBE\u5907\u7BA1" and i want to display it. I tried following things already without any luck. 1) printf("%s",L("\u8BBE\u5907\u7BA1")); 2) printf("%lc",0x8BBE); 3) setlocale followed by fwide followed by wprintf 4) also changed the local manually... (3 Replies)
Discussion started by: jackdorso
3 Replies

3. AIX

problem with Unicode characters insertion

hi, I have a problem with unicode chars ( chinese, japanese etc ) insertion using sqlplus prompt. When i wrote a proc program for it i am able to create records. But when i fore the same query on sql prompt it stores reverse ????? ..some junk. widechar columns are mapped with NVARCHAR datatype.... (0 Replies)
Discussion started by: suman_jakkula
0 Replies

4. Shell Programming and Scripting

Help replacing or scrubbing unicode characters

I have a csv (tab delimited) file that is created by an application (that I didn't write). Every so often it throw out a <U+FEFF> (Zero Width no break space) character at the begining of a tabbed field. The charcater is invisible to some editors, but it shows up bolded in less. The issue is... (3 Replies)
Discussion started by: roninuta
3 Replies

5. UNIX for Dummies Questions & Answers

remove special and unicode characters

Hi, How do I remove the lines where special characters or Unicode characters appear? The following query does work but I wonder if there is a better way. cat test.txt | egrep -v '\)|#|,|&|-|\(|\\|\/|\.' The following lines show that my query is incomplete. Warning: The word "*Khan" is... (1 Reply)
Discussion started by: shantanuo
1 Replies

6. Programming

How to make gl_get_line read unicode characters

Hi, My program uses gl_get_line from libtecla to get user input from terminal. It works fine as long as I enter English at the terminal prompt. However, if I enter other languages, such as Chinese characters, either by typing in or cut-and-paste, the input characters get cleared from terminal... (5 Replies)
Discussion started by: tdw
5 Replies

7. Shell Programming and Scripting

stty erase ^h not working for backspace

Hi , I have to press shift + Backspace to do backspace on my unix termminal everytime. How can i configure it to a normal backspace only. Please help me here. PFB the contents of the stty -a : dbtgr@hpxi017:/pocuser/C5/aimsys/dbtgr> stty -a speed 38400 baud; line = 0; rows = 35; columns =... (4 Replies)
Discussion started by: kunwar
4 Replies

8. Solaris

[SOLVED] Backspace not working!!!!!

Hi friends, Hope u r doing well. It is a very strange problem that I've never faced when I used linux or freebsd. When a type a command in Solaris 10, and if I make a mistake, the backspace doesn't work, when I press the backspace key three times forexample, this is what I get, ^H ^H ^H. The same... (2 Replies)
Discussion started by: gabam
2 Replies

9. Shell Programming and Scripting

Remove ^? characters in shell variables on using backspace

Friends, I observed a peculiar problem in shell. if I set a variable using standard input and backspace was used by the user, then the variable get ^? characters embedded in the variable. ### echo "Enter value for X=" read X echo $X expr $X + 1 ### If the variable is echoed, then there... (3 Replies)
Discussion started by: sachinverma
3 Replies

10. Shell Programming and Scripting

Display unicode characters in zos shell

Hi all, I have a shell script that has several strings with \uxxxx characters distributed within. I would like to display these characters when I execute the script and echo the strings. I am running on zos in an sh environment. Some strings look like this: "Chcete-li pou\u017e\u00edt" <---... (1 Reply)
Discussion started by: adam.wis
1 Replies
PERLTW(1)						 Perl Programmers Reference Guide						 PERLTW(1)

NAME
perltw - XXXX Perl XX DESCRIPTION
XXXX Perl XXX! X 5.8.0 XXX, Perl XXXXXX Unicode (XXX) XX, XXXXXXXXXXXXXXXXXXX; CJK (XXX) XXXXXXXX. Unicode XXXXXXX, XXXXXXXXXXXX: XXXX, XXXX, XXXXXXXX (XXX, XXXX, XXXX, XXXX, XXX, XXXX, XX). XXXXXXXXXXXXXX (X PC XXXX). Perl XXX Unicode XXXX. XXX Perl XXXXXXXXX Unicode XX; Perl XXXXXX (XXXXXXXXX) XXX Unicode XXXX. XXXXXXX, XXXXX Unicode XXXXXXXXXXXX, Perl XXX Encode XXXX, XXXXXXXXXXXXXXXXXXX. Encode XXXXXXXXXXXXXXXXX ('big5' XX 'big5-eten'): big5-eten Big5 XX (XXXXXXX) big5-hkscs Big5 + XXXXX, 2001 XX cp950 XXX 950 (Big5 + XXXXXXX) XXXX, X Big5 XXXXXXX Unicode, XXXXXXXX: perl -Mencoding=big5,STDOUT,utf8 -pe1 < file.big5 > file.utf8 Perl XXXX "piconv", XXXXX Perl XXXXXXXXXXX, XXXX: piconv -f big5 -t utf8 < file.big5 > file.utf8 piconv -f utf8 -t big5 < file.utf8 > file.big5 XX, XX encoding XX, XXXXXXXXXXXXXXXXX, XXXX: #!/usr/bin/env perl # XX big5 XXXX; XXXXXXXXXXXXX big5 XX use encoding 'big5', STDIN => 'big5', STDOUT => 'big5'; print length("XX"); # 2 (XXXXXXX) print length('XX'); # 4 (XXXXXXXX) print index("XXXX", "XX"); # -1 (XXXXXXX) print index('XXXX', 'XX'); # 1 (XXXXXXXXX) XXXXXXXX, "X" XXXXXXXX "X" XXXXXXXXXX Big5 XX "X"; "X" XXXXXXXXX "X" XXXXXXXXXX "X". XXXXXX Big5 XXXXXXXXXXX. XXXXXXX XXXXXXXXXXX, XXX CPAN (<http://www.cpan.org/>) XX Encode::HanExtra XX. XXXXXXXXXXX: cccii 1980 XXXXXXXXXXXX euc-tw Unix XXXXX, XX CNS11643 XX 1-7 big5plus XXXXXXXXXXXXX Big5+ big5ext XXXXXXXXXXXXX Big5e XX, Encode::HanConvert XXXXXXXXXXXXXXXX: big5-simp Big5 XXXXX Unicode XXXXXX gbk-trad GBK XXXXX Unicode XXXXXX XXX GBK X Big5 XXXX, XXXXXXXXX b2g.pl X g2b.pl XXXX, XXXXXXXXXXX: use Encode::HanConvert; $euc_cn = big5_to_gb($big5); # X Big5 XX GBK $big5 = gb_to_big5($euc_cn); # X GBK XX Big5 XXXXXX XXX Perl XXXXXXXXX (XXXXXXXXX), XXXXXXX Perl XXX, XX Unicode XXXXX. XX, XXXXXXXXX: XX Perl XXXXX <http://www.perl.com/> Perl XXX (XXXXXXXX) <http://www.cpan.org/> Perl XXXXX (Comprehensive Perl Archive Network) <http://lists.perl.org/> Perl XXXXXX XX Perl XXX <http://www.oreilly.com.tw/product_perl.php?id=index_perl> XXXXXXXXX Perl XX <http://groups.google.com/groups?q=tw.bbs.comp.lang.perl> XX Perl XXXXX (XXXXX BBS X Perl XXX) Perl XXXXX <http://www.pm.org/groups/taiwan.html> XX Perl XXXXX <irc://irc.freenode.org/#perl.tw> Perl.tw XXXXX Unicode XXXX <http://www.unicode.org/> Unicode XXXX (Unicode XXXXXX) <http://www.cl.cam.ac.uk/%7Emgk25/unicode.html> Unix/Linux XX UTF-8 X Unicode XXX XXXXX XXXXXXX <http://www.cpatch.org/> Linux XXXXXXX <http://www.linux.org.tw/CLDP/> SEE ALSO
Encode, Encode::TW, encoding, perluniintro, perlunicode AUTHORS
Jarkko Hietaniemi <jhi@iki.fi> Audrey Tang (XX) <audreyt@audreyt.org> perl v5.16.2 2012-10-11 PERLTW(1)
All times are GMT -4. The time now is 02:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy