For unicode lines to be counted correctly you need to open the file you are about to read with "encoding(UTF-8)" and if you want to print it out, you need to use "use utf8;" pragma.
#!/usr/bin/perl use utf8; use Encode; use strict; use warnings; open(FF, "<:encoding(UTF-8)",'unicode.txt'); while(<FF>){ chomp; my $l = length($_); my $str = "linenr=$. length=$l $_ \n"; if(utf8::is_utf8($str)){ # get rid of the wide character warning print encode('utf-8', $str); }else{ print $str; } } close(FF);
Now it could be your file is encoded in something else than UTF8 (like UTF16), so this might not be your solution yet.
See also how-do-i-find-the-length-of-a-unicode-string-in-perl
edit note: Edited the response to be more precise, as Choroba suggested.
In reply to Re: how to find the length of any line of file
by FreeBeerReekingMonk
in thread how to find the length of any line of file
by lakshmikant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |