perl配置文件读取

perl configuration files reading

您好,我正在使用 Config::Simple 制作 perl 配置文件 而我的配置文件是

[Dialer External]
pass=pass2
user=user2

[Dialer Onboard]
pass=pass1
user=user1

现在我的实际要求是我还必须阅读评论行。 如果我有这样的文件

[Dialer External]
pass=pass2
user=user2

[Dialer Onboard]
pass=pass1
;user=user1

我将能够阅读行 ;user=user1 also.I 知道阅读评论是不公平的。 但是有什么方法可以在 line.With 的评论 Config::Simple 的帮助下读取和写入数据吗?我想这是不可能做到的。

在 perl 中有没有办法做到这一点。 请在这方面提出建议并纠正我。提前致谢。

当然这是可能的 - 但是模块 Config::Simple 就不行了,因为它现在 。我刚刚在 CPAN 中读到 'Retaining comments while writing the configuration files back and/or methods for manipulating comments. Everyone loves comments!' 是该模块的 TODO

你深挖过源码吗?以这样一种方式操作 read() 应该相当简单,即不会忽略带前缀的行,但也会将其推入哈希中。

您可以尝试删除 the semicolon on this line 的源代码。但是您还需要从选项名称的开头删除分号。