Wide character in print at ./RSS.pm line 1606.

I receive six email messages each day with the above Perl error message. For some reason, the script that generates the Pitchfork Reviews RSS feed would generate that error. None of the other RSS scripts would generate the error, despite having highly similar code. The Mozilla Live Bookmarks Converter script on a Spanish technology site (the code comments are in English, even if the description is not) seems to have the same problem. Luckily I ran into the excellent document "Unicode-processing issues in Perl and how to cope with it." In its last section, it explains the cause of the error:

The warning happens when you output a Unicode string to a non-unicode filehandle.

Tired of the email deluge, I made a patch for RSS.pm that seemed to work. Then I went to CPAN to get an unmodified RSS.pm to generate the diff file and realized that I was working with version 1.03, instead of the latest 1.05. I began to cry.

This depression lifted when I realized that the new version had the same error, now at line 1614, instead of line 1606. I edited the new version, cranked up WinMerge and made the following diff:
1614c1614
< open(OUT,">$file") || croak "Cannot open file $file for write: $!";
---
> open(OUT,">:utf8","$file") || croak "Cannot open file $file for write: $!";

Comments

# At 17:40 on March 21, 2005, This is Martey Dodoo wrote:

Oh, Perl

I made a mistake with serious ramifications when I edited RSS.pm. Who knew a > could cause so much trouble? 1614c1614 $file") || croak "Cannot open file $file for write: $!";


> open(OUT,">:utf8",">$file") || croa...

# At 0:18 on August 3, 2005, Martey wrote:

Note to self: switched back to unpatched v1.05 after switching to Dreamhost, in order to avoid the error:

Unknown open() mode '>:utf8' at ./RSS.pm line 1614.

# At 13:17 on November 29, 2007, bsoisoi@mac.com wrote:

I'm glad you blogged this! i was under the impression that utf8 would have been handled by default, but I ran into the same issue with the text() method of WWW::Mechanize::Link

Earlier: North Korean Pots Upbraid US Kettles
Later: The Imperial Congress