Leser: 13
if($line =~ /\x{263a}/){ ... }
1
2
3
4
my @chars = split(//,$line);
foreach my $char(@chars){
if($char =~ /\x{263a}/){ ... }
}
1
2
3
4
5
6
7
8
9
open(INF,"<:utf8",$infile);
while(my $line = <INF>){
chomp($line);
my $stringToCompare = pack "U", 0x263a;
if($line =~ /$stringToCompare/){
print "MATCH IN LINE: $line\n";
}
}
close(INF);
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 26 27 28 29 30 31 32 33 34 35 36 37
use strict; use warnings; use IO::File; use Encode; my $smiley = pack "U", 0x263a; # Zeichen my $bin = Encode::encode('UTF-8', $smiley); # binary f. Zeichen my $file = 'd:/tmp/emos'; # Datei zum Testen anlegen #writefile($file, $bin); # testen ob Zeichen in Datei # Vergleiche Zeichen my $fh = IO::File->new; $fh->open($file, "<:utf8") or die $!; while( my $line = <$fh> ){ chomp $line; # Ausgabe aller Codepoints print "@{[unpack 'U*', $line]}\n"; print "Hier wird gelächelt!\n" if $line =~ /$smiley/; } # Schreibe Bytes in Datei sub writefile{ my $file = shift; my $s = shift; my $fh = IO::File->new; $fh->open($file, O_CREAT|O_TRUNC|O_RDWR|O_BINARY) or die $!; $fh->print("Bitte lächeln und zwar so: $s"); $fh->close; }
1 2 3 4 5 6 7 8 9 10
-!/usr/bin/perl use strict; use warnings; open(my $fh, '<:encoding(UTF-8)', './test.txt') or die($!); while(my $line = <$fh>){ if($line=~/\x{263a}/) { print "gefunden\n"; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/perl use strict; use warnings; open(my $fh, '<:encoding(UTF-8)', './test.txt') or die($!); while(my $line = <$fh>){ if($line=~/\x{263a}/) { print "gefunden Smiley\n"; } if($line=~/\x{1f91e}/) { print "gefunden Cossed Fingers\n"; } } close($fh);