in reply to perltidy and UTF-8 BOM
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: perltidy and UTF-8 BOM
by AnomalousMonk (Archbishop) on May 21, 2018 at 13:57 UTC | |
by haukex (Archbishop) on May 21, 2018 at 14:17 UTC |