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


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

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 |....|