Thread Byte raw format in String umwandeln (Glib::IO::File->get_contents) (18 answers)
Opened by Max_Perlbeginner at 2016-05-31 10:53

Max_Perlbeginner
 2016-05-31 16:51
#184858 #184858
User since
2016-04-04
107 Artikel
BenutzerIn
[default_avatar]
Lieber guest janus,
Danke für Deine Antwort. Leider habe ich nun in der Tat ein Problem mit den Umlauten. Aus mir völlig unverständliche Gründen werden diese, wenn sie mit bspw. gedit in UTF 8 gespeichert werden (was auch die Einstellung meines Systems ist) falsch dargestellt..

use utf8; hab ich aktiviert. Ich hab auch schon $content = pack( 'U*', @{$content} ); versucht, aber leider ohne Erfolg...

Die relevanten Zeilen meines Codes sehen bislang folgendermaßen aus:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl

package MyWin
use utf8;
use Encode;
[...]
sub open_response_cb {
# $file is the file that we get from the FileChooserDialog
$file = $open_dialog->get_file();

# an empty string (provisionally)
#my $content = '';

# load the content of the file into memory:
# success is a boolean depending on the success of the operation
# content is self-explanatory
# etags is an entity tag (can be used to quickly determine if the
# file has been modified from the version on the file system)
my ($success, $content, $etags) = Glib::IO::File::load_contents($file) or print "Error:";
#my $content_raw = Dumper $content;
#print "DUMPER: $content_raw \n";
# Ich hab auch pack('C*' ...) probiert
$content = pack( 'U*', @{$content} );
my $length = length(Encode::encode_utf8($content));
$buffer->set_text($content,$length);

View full thread Byte raw format in String umwandeln (Glib::IO::File->get_contents)