On Fri, Dec 19, 2014 at 07:17:00AM +0100, Marek Stepanek wrote:
>
> Thank you Charlie!
>
> I tried nearly everything. I added "use utf8" as you suggested; I saved
> the input file with every imaginable encoding (utf-16/8 with or without
> BOM) - no help. The search of \x{D83D}\x{DE18} in BBEdit is working.
>
> I discovered in the suggested perlunicode the possibility to look for
> the official Unicode character name like \N{FACE THROWING A KISS} Not
> working either :-(
>
> Is the Perl guru Ronald in this group not any more? Somebody else taking
> this challange?
Unfortunately I am not a Unicode guru.
That said, what works depends on how Perl sees the content. If it's
seeing the emoji as a single character, then /\x{1F618}/ should work (as
should \N{FACE THROWING A KISS} or the literal character). To make Perl
see the emoji as a single character, you need to tell Perl the file
contains UTF-8 data. There are several ways to do this.
When opening a file:
open my $fh, '<:encoding(utf8)', $file
or die "Can't open $file: $!\n";
On an existing filehandle:
binmode($fh, ':encoding(utf8)');
On the command line, for STDIN:
perl -CI
On the command line, for files:
perl -Ci
(Those two I found in the perlrun documentation.)
You might want the same encoding for the output, as well. For the command
line, that's -CO and -Co.
So, this might work for you:
#!/usr/bin/perl -p -CIOio
use strict;
use warnings;
s!\x{1F618}!\\includegraphics[height=15pt]{/Users/mstep/Documents/private_txt/anette/pix/emo01.png}!g;
Note that -C is one of those options that, when specified on the #! line,
also needs to be specified on the command line. So, if you save the above
script as script.pl, `./script.pl file.txt` will work, but
`perl script.pl file.txt` would need to be `perl -CIOio script.pl file.txt`.
Alternatively, you can use binmode() as I mentioned.
HTH,
Ronald
--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].