Hallo, ich habe ein Perl Script das so aussieht:
Nur bei größeren Dateien ist es SEHR langsam! Ich vermute das es an der Unicode Bibliothek liegt.
Gibt es einen anderen Grund dafür?
Oder kann ich statt der Unicode Binliothek mit der Encode (http://search.cpan.org/dist/Encode/Encode.pm) oder http://perldoc.perl.org/perlunicode.html sp programmieren?
Code:
#!/usr/bin/perl -w use strict; use Encode qw(encode_utf8); use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset); #sub inascii{ # return <<'END'; #0000 007F #END #} binmode STDIN, ':encoding(UTF-8)'; #my $c2iso5 = Text::Iconv->new("UTF-8", "ISO-8859-5"); #my $c2iso2 = Text::Iconv->new("UTF-8", "ISO-8859-2"); my $LAT = "</KYR>"; my $CYR = "<KYR>"; my $out=""; while(my $line = <STDIN>) { chomp $line; if ( $line =~ /([^\p{inlatin2}\p{incyr}])/ ){ die "unknown character in line $.: $1 ".sprintf("%04x",ord($1))."$/"; } while ( $line =~ /(?=.)(\p{inlatin2}*)(\p{incyr}*)/g ) { $out.=from_utf8({ -string => "$1" , -charset => 'ISO-8859-2' }) unless ( "$1" eq "" ); $out.=$CYR.from_utf8({ -string => "$2" , -charset => 'ISO-8859-5' }).$LAT unless ( from_utf8({ -string => "$2" , -charset => 'ISO-8859-5' }) eq "" ); } $out.=$/; print $out; $out=""; } exit;
Gibt es einen anderen Grund dafür?
Oder kann ich statt der Unicode Binliothek mit der Encode (http://search.cpan.org/dist/Encode/Encode.pm) oder http://perldoc.perl.org/perlunicode.html sp programmieren?
Comment