Perl Config :: Tiny-> read()不处理CRLF

Wes*_*Wes 0 perl config perl-io

我在Windows 10下使用Perl和Ubuntu.我想使用Perl Config :: Tiny模块来读取文件名和其他配置数据.当我在Linux中读取在Windows下创建的配置文件时,它将Carriage Returns保留在值的末尾.我目前通过在Linux下制作配置文件的临时副本来解决这个问题.

有没有办法告诉Config :: Tiny-> read()打开配置文件与行结束处理,做我想要的?

这是我当前代码的一个片段:

use Config::Tiny;
my $configfile = 'MyScript.ini';
# ; MyScript.ini file looks like:
# [MyScript]
# infilename=Dii.fwdata
# outfilename=Dii.1.fwdata
# logfilename=Dii.ReverseMerge.log
# someotherconfig=xyzzy

say STDERR "read config from:$configfile";
# Windows CRLF nonsense
if ( $^O =~ /linux/)  {
    `perl -pe 's/\r\n/\n/' < $configfile  >/tmp/$configfile `;
    }
my $config = Config::Tiny->read($configfile);
my $infilename = $config->{MyScript}->{infilename};
my $outfilename = $config->{MyScript}->{outfilename};
# ... etc,
Run Code Online (Sandbox Code Playgroud)

Cor*_*ion 6

只需传递crlf"编码"即可.然后将其用作打开模式:

$Config = Config::Tiny->read( 'file.conf', 'crlf' ); # Neither ':' nor '<:' prefix!
Run Code Online (Sandbox Code Playgroud)

也可以看看

https://metacpan.org/pod/Config::Tiny