Reputation: 157
i need to load two different config files in perl using YAML,
use YAML qw'LoadFile';
then in first function i used
my $conf = LoadFile('/config/test.yaml'); my $serve = $conf->{test};
and in 2nd one i used
my $conf = LoadFile( '/config/XYZ.yaml'); my $key = $conf->{xyz};
now the in this case if i used only one file then its works fine, but used them simultaneously gives me error. Do anyone know its reason?
Upvotes: 0
Views: 405
Reputation: 69224
I noticed that in your question, you talked about loading the two files in different functions. So I altered Borodin's answer to better reflect what I think you are doing.
#!/usr/bin/perl
use strict;
use warnings 'all';
use feature 'say';
use YAML qw/ LoadFile /;
sub load_test {
my $conf = LoadFile('test.yaml');
my $test = $conf->{test};
say $test;
}
sub load_xyz {
my $conf = LoadFile('XYZ.yaml');
my $xyz = $conf->{xyz};
say $xyz;
}
load_test();
load_xyz();
When I run that, I get:
value for test
value for xyz
So I can't see what the problem is. If you want more help then you are going to need to give us a lot more detail.
Upvotes: 1
Reputation: 126722
I'm afraid you haven't given anywhere near enough information for us to diagnose your problem, but here's a demonstration of loading two different YAML files, as you asked. As you can see, it's pretty much identical to what you have shown of your own code, which should work fine
---
test: value for test
---
xyz: value for xyz
use strict;
use warnings 'all';
use feature 'say';
use YAML qw/ LoadFile /;
my $conf = LoadFile('test.yaml');
say $conf->{test};
$conf = LoadFile('XYZ.yaml');
say $conf->{xyz};
value for test
value for xyz
Upvotes: 1