Simple example of using data from a YAML configuration file in a Perl script

后端 未结 3 945
甜味超标
甜味超标 2021-02-06 00:46

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 h

3条回答
  •  南笙
    南笙 (楼主)
    2021-02-06 01:30

    Try dumping out the configuration you want.

    use strict;
    use warnings;
    
    use YAML;
    
    my %settings = (
            foo => 1,
            bar => [qw/one two three/],
    );
    
    print Dump(\%settings);
    

    This prints

    ---
    bar:
      - one
      - two
      - three
    foo: 1
    

    Also, wikipedia has a good overview of YAML if the specification is a bit too dense.

提交回复
热议问题