在 Perl 脚本中使用 YAML 配置文件中的数据的简单示例 [英] Simple example of using data from a YAML configuration file in a Perl script

查看:31
本文介绍了在 Perl 脚本中使用 YAML 配置文件中的数据的简单示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个 YAML 文件来存储 Perl 脚本的一些配置数据.这似乎应该很容易,但我无法解决,我想如果我只有一个简单的例子可以复制我会没事的.我想做这样的事情:

I need to create a YAML file to store some configuration data for a Perl script. This seems like it should be really easy but I haven't been able to work it out, I think if I had just one simple example to copy I'd be fine. I want to do something like this:

-----test.yaml-----
image_width: 500
show_values: 0
-------------------

------test.perl------
use YAML;

my (%settings) = Load('test.yaml');
print "The image width is", $settings{image_width};
---------------------

推荐答案

试试这个:

#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use YAML qw(LoadFile);

my $settings = LoadFile('test.yaml');
say "The image width is ", $settings->{image_width};

——迈克尔

这篇关于在 Perl 脚本中使用 YAML 配置文件中的数据的简单示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆