You can write your own conversion module for PerlIO and use it with :via(MODULE) . Your module can transfer data via Text::Iconv to convert from one encoding to another.
This method is described in the PerlIO::via(3pm) manual. In short, you will need to create your own module, for example. PerlIO::via::Example , i.e. you create the PerlIO/via directory and put Example.pm there with the following contents:
package PerlIO::via::Example; use strict; use warnings; use Text::Iconv; my $converter = Text::Iconv->new("windows-1252", "utf-8"); sub PUSHED { my ($class, $mode, $fh) = @_;
and then use it in open , like here:
use strict; use warnings; use PerlIO::via::Example; open(my $fh, "<:via(Example)", "input.txt"); while (<$fh>) { print; } close $fh;
source share