So I’m trying to write a perl script to read in a file encoded in Latin-1. For some reason, this just isn’t working out. When I try to do a simple search for a character that I know is in the file (it’s in the first line), nothing shows up. I’m using use encoding “iso 8859-1”; below, but I’ve also tried binmode(STDIN, “:utf8”);. Any suggestions on what I might be doing wrong, and how to make it right?
use encoding "iso 8859-1";
while(<>)
{
if(/ó/gi)
{
print "Found one!\n";
}
}
Don’t use the
use encodingpragma: it’s broken.Either specify the encoding here:
or put it in the open itself:
or
binmodeit after opening:If you’re using
<ARGV>, thenuse openis probably easiest.Don’t forget to set the encoding on your output streams, too.