【问题标题】:How to read INI file entries into a hashtable?如何将 INI 文件条目读入哈希表?
【发布时间】:2014-02-12 13:07:11
【问题描述】:

如何将 INI 文件中的条目添加到哈希表?

我的 INI 文件看起来像这样......

[Channel 0]
Input = 0
Output = 0
CirUpdateRate = 10000 Hz
CirSourceFile = ..\..\MAT\mymodel.mat
CirControlFile = mymodel_0_S1_T4.sim

[Channel 1]
Input = 1
Output = 1
CirUpdateRate = 10000 Hz
CirSourceFile = ..\..\MAT\mymodel.mat
CirControlFile = mymodel_1_S1_T4.sim

如何将每个变量和值插入哈希表

我能否区分或访问 [Channel 0] 下的变量 InputInput `[Channel 1]?

【问题讨论】:

    标签: perl hash ini


    【解决方案1】:

    根据请求添加评论作为答案。

    您可以使用Config::INI

    根据概要,您可以:

    use Config::INI::Reader; 
    my $config_hash = Config::INI::Reader->read_file('config.ini');
    

    【讨论】:

    • 使用 $config_hash 如何访问 [Channel 0] 和 [Channel 1] 中的“输入”。
    • $config_hash->{'Channel 0'}{'Input'}
    • $config_hash--> 这个变量应该是hash变量(hash变量前面有一个百分号(%))?
    • $config_hash 是一个 reference 到一个哈希
    • @LokeshRGowda 使用cpan 命令安装缺少的模块
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-29
    • 2010-09-13
    • 2012-05-15
    • 2011-06-07
    • 1970-01-01
    • 2021-06-01
    相关资源
    最近更新 更多