in reply to Recover data from a config file to use them with Selenium::Remote::Driver

Hi Chaoui05,

It looks like your config file is using array ref constructors [...] where it should be using hash ref constructors {...}. If you can change your configuration file, that would be the easiest way to fix up your configuration. Then you can use all the normal methods of accessing complex data structures, see e.g. perlreftut and "hash of hashes" in perldsc.

If you can't change the format of the file, then since the array refs appear to contain a list of key/value pairs, you can simply assign them to a hash, for example:

my %programs = @{ $config->{programs} }; for my $prog (values %programs) { my %param = @{ $prog->{parameters} }; print $param{Count_id},"\n"; }

Will print the Count_id value for each "program". One caveat is that this will silently clobber any "programs" and "parameters" with the same name. Whether that is a problem in your case depends on what the rest of your configuration file looks like.

Hope this helps,
-- Hauke D

Updated wording.

Replies are listed 'Best First'.
Re^2: Recover data from a config file to use them with Selenium::Remote::Driver
by Chaoui05 (Scribe) on Jun 02, 2016 at 10:38 UTC

    Hi haukex

    First, thanks for the reply.I wasn't exceptionally available until now.

    Concerning the Array, yes. I can't change conf's file. And it seems to be the good approach. Perfect.

    Thanks again and yes it helps

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

      Hi Chaoui05,

      I forgot to mention another caveat: hash ordering is random, which means that in the sample code I showed the "programs" and "parameters" will lose their ordering. The arrayrefs used in your config file would have maintained their ordering, and if that is important, you'll have to use another method to access the array refs, like walking the array two elements at a time.

      Regards,
      -- Hauke D

        Hi haukex . Thanks for the caveat and the reminder.

        For the moment it's not a problem but you do well to say it me

        Thanks again haukex, i appreciate

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