Leser: 17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/perl use 5.010; use strict; use warnings; use utf8; use locale; use POSIX qw( locale_h ); my $locale = setlocale( LC_CTYPE ); say $locale; # de_DE.UTF-8 my $string = 'abcäöüß'; my @match = $string =~ /(\w)/g; say "@match"; # a b c
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/usr/bin/perl use 5.010; use strict; use warnings; use utf8; use Encode qw( encode ); my $string = 'abcäöüß'; my @match = $string =~ /(\w)/g; say encode( 'utf-8', "@match" ); # a b c ä ö ü ß
1 2 3 4 5 6 7 8 9
#!/usr/bin/perl -w use 5.010; use strict; use utf8; use Encode qw( encode ); my $string = 'abcäöüß'; my @match = $string =~ /(\w)/g; say encode( 'utf-8', "@match" ); # a b c ä ö ü ß
1 2 3 4 5 6 7 8 9 10
#!/usr/bin/perl -w use 5.010; use strict; use locale; # de_DE.UTF-8 use utf8; use Encode qw( encode ); my $string = 'abcäöüß'; my @match = $string =~ /([[:word:]])/g; say encode( 'utf8', "@match" ); # a b c ä ö ü ß
1 2 3 4 5 6 7 8 9 10 11 12
#!/usr/bin/perl -w use 5.010; use strict; use utf8; use locale; use POSIX qw( locale_h ); use Encode qw( encode ); my $latin_locale = setlocale( LC_CTYPE, 'de_DE.ISO8859-1' ); my $string = 'abcäöüß'; my @match = $string =~ /(\w)/g; say encode( 'utf-8', "@match" ); # a b c ä ö ü ß
Guest GastHabe ich richtig geraten:
beim letzten Beispiel muß ich mit utf-8 encoden, weil setlocale sich nicht auf meine Konsole auswirkt und diese auf utf8 eingestellt ist?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/usr/bin/perl -w use 5.010; use strict; use utf8; my $string = 'abcäöüß'; # Achtung, der Quelltext muss utf8-kodiert sein my @match = $string =~ /[[:word:]]/g; if (${^UTF8LOCALE}) { # Erkennt, ob utf8 ausgegeben werden soll # Ausgaben nach STDOUT werden nach utf8 konvertiert binmode STDOUT, ':encoding(utf8)'; } say "@match"; # a b c ä ö ü ß