Chedi Bechikh Chedi Bechikh - 3 months ago 51
Perl Question

How to detect emoji as unicode in Perl?

i have text file that contain emoji unicode caracter for exemple

Answer Source

If you look at perldoc perlre for \N, you see that it means "named Unicode character or character sequence".

You can use this instead:

if ($ligne =~ m/\N{U+1F60D}/)
# or
if ($ligne =~ m/\x{1F60D}/)

Edit: It's also described in the link you posted,

Edit: The content you read is probably not decoded. You want:

use Encode;
my $ligne = decode_utf8 $_;

or simply open the file directly in utf8 mode:

open my $fh, "<:encoding(UTF-8)", $filename or die "Could not open $filename: $!";
while (my $ligne = <$fh>) {
    if ($ligne =~ m/\N{U+1F60D}/) { ... }

You never showed how you open the filehandle called FIC, so I assumed it was utf8 decoded. Here is another good tutorial about unicode in perl:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download