Chaoui05 has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks ! I have an issue a little bit difficult.

I would like to recover with Perl code some data automatically in a config file and use them in a test with Selenium::Remote::Driver module. Mainly using "send_keys("...")"

My config file is following : work.conf :

my $folder = 'E:\FOLDER\Test\WEB'; { license => 'kit-licence.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', ] }, ] };
And my file test is following:
#test.pl use Modern::Perl; my $config = do 'work.conf'; use Data::Dumper; say Dumper( $config );

And i would like in my test.pl , my file test, to recover values from my HASH parameters , i.e. for Count_id recover '06 (Viktor)' etc..

And after have recovered them , i would like to send them in my some input in my web page, using method from Selenium::Remote::Driver :For example:

$driver->find_element('login','class')->send_keys("06 (Viktor)");

Many Thanks fro any help!!

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

Replies are listed 'Best First'.
Re: Recover data from a config file to use them with Selenium::Remote::Driver
by haukex (Archbishop) on Jun 01, 2016 at 16:33 UTC

    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.

      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