我正在寻找解析 YAML 文档的帮助。具体来说,我不确定主机打印/访问“卷”元素。任何帮助将不胜感激。提前致谢!
perl 代码:
#!/usr/bin/perl
use YAML::Tiny;
# Open the config
$yaml = YAML::Tiny->read( 'file.yml' );
# Reading properties
my $root = $yaml->[0]->{rootproperty};
my $one = $yaml->[0]->{physical_interfaces}->{e0a};
my $Foo = $yaml->[0]->{physical_interfaces}->{e0b};
print "$root\n";
print "$one\n";
print "$volume1\n";
我的 yaml 文件如下所示:file.yaml
---
rootproperty: netapp1
is_netapp: Yes
netapp_mode: 7mode
is_metro_cluster: Yes
is_vseries: Yes
is_flexcache_origin: No
snapmirror:
enabled: Yes
destination: Yes
lag_threshold: 2300
physical_interfaces:
e0a: netapp1-e0
e0b: netapp1-e1
mgt: netapp1-mgt
volumes:
- volume: vol1
reserve: 50
sched: 6 42 0
- volume: vol2
reserve: 20
sched: 0 3 0