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:

#test.pl use Modern::Perl; my $config = do 'work.conf'; use Data::Dumper; say Dumper( $config );
To get parameters in Programs for Viktor for example, i can do this :
%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":

license => [ 'kit-licence.zip', 'kit-work.zip' ], programs => [..
I would like to get the license by name of each one. For example, 'kit-license.zip'..

And not by "hard coding" like that:

use File::Spec::Functions qw/catfile/; my $filename = catfile($::svn, ${$config->{license}}[0]); my $filename1 = catfile($::svn, ${$config->{license}}[1]);
Perhaps in a loop, but i didn't find .

Many thanks in advance for help !!

PS : Don't ask me why they are all divorced. I really don't know.

*****Lost in translation****TIMTOWTOI****

Replies are listed 'Best First'.
Re: Loops for Hash in a config.file
by hippo (Archbishop) on Jun 14, 2016 at 11:00 UTC

    perldsc is the document to read. I suggest you take the time to work your way through it and see how to use references in large data structures. That will save you from having to ask similar related questions in future.

    Good luck.

      Thanks Hippo.

      But it's not exactly the same questions i posted if you read all.

      In all cases, Thanks for the link i will read it

      *****Lost in translation****TIMTOWTOI****

        No, it isn't exactly the same question. However it is a similar and related question. Given the number of answers to your various questions in the other thread and the apparent situation that you don't seem to have been able to apply the knowledge learned there to this question, there's no point in us continuing to answer similar, related questions ad infinitum.

        The point of the Monastery is education. If you aren't learning then there's no point teaching. Do read the Data Structures Cookbook. If you subsequently have problems or do not understand something written in the Cookbook then by all means ask.