http://www.perlmonks.org?node_id=1214983


in reply to Re: perltidy and UTF-8 BOM
in thread perltidy and UTF-8 BOM

... s/\A\x{FEFF}// ... print "\x{FEFF}" ...

Again, a total UTF-8 n00b (or maybe nob) here, but isn't the UTF-8 BOM  "\xEF\xBB\xBF" (239 187 191) (see this and the perltidy complaint cited in the OP)? (And  \x{FEFF} works out to decimal 65279.)


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^3: perltidy and UTF-8 BOM
by haukex (Chancellor) on May 21, 2018 at 14:17 UTC

    The Byte order mark is the Unicode character U+FEFF, and depending on the encoding it is encoded as different bytes - see "Byte order marks by encoding" on the same Wikipedia page. Because I've changed STDIN and STDOUT to be UTF-8 with the command-line switch -CS, I can use the Unicode representation and don't need to look at the bytes (although I could do that too, but I figured since everything is UTF-8 already anyway...).

    $ perl -wMstrict -CSD -e 'print "\x{FEFF}"' | hexdump -C 00000000 ef bb bf |...| $ perl -wMstrict -e 'binmode STDOUT, ":raw:encoding(UTF-8)"; print + "\x{FEFF}"' | hexdump -C 00000000 ef bb bf |...| $ perl -wMstrict -e 'binmode STDOUT, ":raw:encoding(UTF-16-LE)"; print + "\x{FEFF}"' | hexdump -C 00000000 ff fe |..| $ perl -wMstrict -e 'binmode STDOUT, ":raw:encoding(UTF-16-BE)"; print + "\x{FEFF}"' | hexdump -C 00000000 fe ff |..| $ perl -wMstrict -e 'binmode STDOUT, ":raw:encoding(UTF-32-LE)"; print + "\x{FEFF}"' | hexdump -C 00000000 ff fe 00 00 |....| $ perl -wMstrict -e 'binmode STDOUT, ":raw:encoding(UTF-32-BE)"; print + "\x{FEFF}"' | hexdump -C 00000000 00 00 fe ff |....|