It seems that Perl::Tidy only supports UTF-8 and the default ("none") encodings, and it does not recognize the BOM - when I run it with the -utf8 switch on a UTF-8 file with a BOM, I get "unexpected character decimal 65279 () in script".

While the UTF-8 BOM might be useful to your text editor, it isn't really useful to Perl: it is completely ignored, and you still need an explicit use utf8; (see the caveats at the beginning of perlunicode). Note this is different for UTF-16, where the BOM will cause Perl to automatically use that encoding. But anyway, you might want to consider whether you need the BOM, since many text editors default to UTF-8 anyway, and if you're worried someone might take your UTF-8 encoded Perl source and open it with an incorrect encoding, remember that there's still the use utf8; at the top of the file. In fact, I sometimes write "use utf8; # Euro Symbol: " so that I have an immediate visual clue as to whether the text editor used the right encoding (why I like that symbol, plus it's easy to type on my German keyboard :-) ).

Other than filing a bug in the issue tracker and/or writing a patch, you could work around the issue by writing a small wrapper for perltidy that strips the BOM first and adds it back in again after:

perl -wM5.012 -CDS -pe '$.==1 && s/\A\x{FEFF}//' utf8_bom.pl \ | perltidy -utf8 \ | perl -wM5.012 -CDS -pe 'INIT{print "\x{FEFF}"}' \ > utf8_bom_tidy.pl

In reply to Re: perltidy and UTF-8 BOM by haukex
in thread perltidy and UTF-8 BOM by morelenmir

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":