![]() |
|
P is for Practical | |
PerlMonks |
Re^7: Rogue character(s) at start of JSON file (BOM; dumping references)by pryrt (Abbot) |
on Jan 19, 2023 at 18:49 UTC ( #11149700=note: print w/replies, xml ) | Need Help?? |
not removed with $str =~ s/^\x{feff}//; compare how the behavior changes with open my $fh, '<:encoding(UTF-8)', '../data/publicextract.charity.json' or die "Unable to read Charity JSON File"; compared to the open line you currently use. If you want perl to treat the bytes in the file as UTF-8, and thus be able to use s/^\x{feff}/, you have to tell perl to read the file as UTF-8¹. If you want perl to continue to read the file as a series of bytes (not using the UTF-8 encoding), then leave your open as-is, and have your regex instead either search for the three bytes in octal with s/^\357\273\277// or in hex with s/^\xEF\xBB\xBF//.
¹: or, not shown, use Encode::decode('UTF-8', $octets) from Encode
In Section
Seekers of Perl Wisdom
|
|