Quote72 97 108 108 111 32 87 101 108 116
QuoteAn unsigned integer guaranteed to be 8 bits on all platforms. Values of this type can range from 0 to G_MAXUINT8 (= 255).
print chr for qw(72 97 108 108 111 32 87 101 108 116);
1 2 3 4 5 6 7 8 9 10 11 12
use strict; use warnings; use 5.010; use Data::Dumper; my $buffer_ref = [72,97,108,108,111,32,87,101,108,116]; # Puffer mit Bytes ähnlich deines $content say Dumper $buffer_ref; my $string = pack "C*",@{$buffer_ref}; # in eine Zeichenkette umwandeln say Dumper $string;
Guest janusWieso umständlich?Umständlicher gehts ja nun wirklich nicht. Es wäre besser Du guckst Dir mal an, wie mit native Perl Dateien gelesen und geschrieben werden.
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
# Layer laden # Lade den Data Access Layer $self->{DAL} = FastEAV->new( file => $self->{FILEDIR}."/".$self->eav('file'), lock => $self->eav('edit') ? 1 : 0, auto => 0 ) or die $@; # einen Hash einchecken my %hunt = ( title => $self->trim($self->param('title')), descr => $descr, body => $self->trim($self->param('body')), ); # Neue Nummer oder vorhandene Nummer my $number = $self->param('lfdnr') ? $self->param('lfdnr') : $self->{DAL}->lfdnr; $self->{STASH}{lfdnr} = $number; $self->{DAL}->checkin($number, %hunt) or die $@; $self->{DAL}->write or die $@;
my @content = unpack "C*", $current_contents;
1 2 3 4 5 6 7 8
use strict; use warnings; use utf8; # Zeichenorientiert print "@{[unpack 'C*', 'ä€']}\n"; # 228 8364 Das sind die Codepoints no utf8; # byteorientiert print "@{[unpack 'C*', 'ä€']}\n"; # 195 164 226 130 172 Das sind die Byte-Wertigkeiten
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);
1
2
3
4
# Zunächst wandeln wir die Bytes in einen Bytestring um
my $content = pack "C*", @{$raw_content};
# Diesen Bytestring dekodieren wir in das utf8 Format
my $content_utf8 = decode('utf-8', $content);
1
2
3
4
# Den Textstring im UTF8 Format in einen Bytestring umwandeln
my $content_utf8 = encode('utf-8', $content);
# Den Bytestring wieder in Bytes umwandeln
my @contents = unpack "C*", $content_utf8;
Guest janus1) gar nichts
perldoc utf8Do not use this pragma for anything else than telling Perl that your script is written in UTF-8.
QuoteEnabling the utf8 pragma has the following effect:
Bytes in the source text that are not in the ASCII character set will be treated as being part of a literal UTF-8 sequence. This includes most literals such as identifier names, string constants, and constant regular expression patterns.
2016-05-31T16:36:19 Max_Perlbeginner1) Was macht denn das Pragma use utf8;, wenn ich trotzdem vor dem Speichern den Bytestring mit encode('utf-8', $content) extra ins utf8 Format umwandeln muss?
Guest janus1) gar nichts
QuoteWas macht denn das Pragma use utf8;