package MyLib;
use strict; use warnings;
sub get_data {
my %hash = (
A => {
a => 1,
b => 2,
},
B => {
a => 3,
b => 4,
},
);
return \%hash;
}
1;
####
use strict; use warnings;
use MyLib;
my $hashref = MyLib::get_data();
my %hash = %{ $hashref };
for my $key ( keys %hash ) {
printf( 'Value of `a` in %s is %s', $key, $hash{ $key }->{'a'} );
}
__END__
##
##
---
A:
a: 1
b: 2
B:
a: 3
b: 4
##
##
use strict; use warnings;
use YAML qw/ LoadFile /;
my $hashref = LoadFile('my_data.yaml');
my %hash = %{ $hashref };
for my $key ( keys %hash ) {
printf( "Value of `a` in %s is %s', $key, $hash{ $key }->{'a'} );
}
__END__