Chaoui05 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks !
I have to request your wisdom again.
I have a config.file to do some tests and i would like to get some values from this one also.
Here my config.file :
my $folder = 'E:\FOLDER\Test\WEB'; { license => [ 'kit-licence.zip', 'kit-work.zip' ], programs => [ #template society =>\%program_work 'VIKTOR DESCRIPTION PRODUCT' => { name => 'VIKTOR ', parameters => [ Count_id => '06 ( +Viktor)', Birth_date => '1995-04-3 +0', Marriage_date => '2014-05-26', Divorce_date => '2015-03-30', Activities_folder => $folder. +'\VIKTOR\independent worker', Activities_format => 'Enterpr +ise Format (V35)', Description_File_from => $folder.'\VI +KTOR\FILE\description.xlm', ] }, 'OLIVER NEW OBJECT' => { name => 'OLIVER ', parameters => [ Count_id => '06 ( +oliver)', Birth_date => '1990-04-3 +0', Marriage_date => '2011-03-26', Divorce_date => '2014-01-30', Activities_folder => $folder. +'\OLIVER\independent worker', Activities_format => 'Enterpr +ise Format (V35)', Description_File_from => $folder.'\OL +IVER\FILE\description.xlm', ] }, ] };
My file test is following:
To get parameters in Programs for Viktor for example, i can do this :#test.pl use Modern::Perl; my $config = do 'work.conf'; use Data::Dumper; say Dumper( $config );
%programs = @{ $config->{programs} }; for my $prog (values %programs) { my %param = @{ $prog->{parameters} }; for my $name (sort keys %param){ print $name, ': ', $param{$name},"\n"; } }
But in my case, i want to be able to get parameters for every user. Here it's just for Viktor. I would like to get them for Oliver or for an other user. For that, and to differentiate all users, i have to use the "template society" which is the name to diffenciate every users . For example, for Viktor, it's :"VIKTOR DESCRIPTION PRODUCT".For Oliver :"OLIVER NEW OBJECT"..
How can i do that ?
Same thing for "License":
I would like to get the license by name of each one. For example, 'kit-license.zip'..license => [ 'kit-licence.zip', 'kit-work.zip' ], programs => [..
And not by "hard coding" like that:
Perhaps in a loop, but i didn't find .use File::Spec::Functions qw/catfile/; my $filename = catfile($::svn, ${$config->{license}}[0]); my $filename1 = catfile($::svn, ${$config->{license}}[1]);
Many thanks in advance for help !!
PS : Don't ask me why they are all divorced. I really don't know.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Loops for Hash in a config.file
by hippo (Archbishop) on Jun 14, 2016 at 11:00 UTC | |
by Chaoui05 (Scribe) on Jun 14, 2016 at 11:20 UTC | |
by hippo (Archbishop) on Jun 14, 2016 at 11:28 UTC | |
by Chaoui05 (Scribe) on Jun 14, 2016 at 11:52 UTC | |
by stevieb (Canon) on Jun 14, 2016 at 12:26 UTC | |
|