t-rex has asked for the wisdom of the Perl Monks concerning the following question:

hello monks, I am parsing a yaml file and its very complex taking reference, has anyone tried it before ,pls help me with this, i have read much documentation but to no use.

#my main.pl where i parse the yaml file $input_file = $ARGV[0]; print "Input File = $input_file\n"; # parse the yaml file $yaml_input = YAML::XS::LoadFile("$input_file"); #these are my parse functions : sub parse_yaml_run_tgt($) { my ($yaml_input) = @_; $run_target_platforms = $yaml_input->{run_target_platforms}; @run_target_id = (); @run_target_controls = (); @run_target_con_info = (); my $i = 0; for my $run_index (@$run_target_platforms) { $run_target_id[$i] = $run_index->{run_target_id}; $run_target_controls[$i] = $run_target_id[$i]->{target_control +s}; $run_target_types[$i] = $run_target_controls[$i]->{run_target_ +type}; $run_target_active[$i] = $run_target_controls[$i]->{run_target +_active}; $run_target_con_info[$i] = $run_target_id[$i]->{target_connect +ion_info}; $run_target_hostname[$i] = $run_target_con_info[$i]->{run_targ +et_hostname}; $i++; } } sub parse_yaml_standalone($) { my ($yaml_input) = @_; $standalone_exec = $yaml_input->{standalone_execution}; $utpsm_exec = $standalone_exec->{utpsm_executable}; $se_hostname = $utpsm_exec->{hostname}; $se_tgt_list = $standalone_exec->{target_list}; $se_rulesfile = $standalone_exec->{rulesfile}; } #and this is my yaml file : ################################################ # Input file for uTPSM regression test control # ################################################ test_control: standalone_execution: yes code_checkout: no #yes/no rules_file: - rules_file_id: &rulesid_01 name: hostname: - rules_file_id: &rulesid_02 name: run_target_platforms: - run_target_id: &runid_01 target_controls: run_target_type: simulator #simulator, emulator , hardware run_target_active: yes target_connection_info: standalone_execution: utpsm_executable: hostname: rulesfile: [*rulesid_01] target_list: [*runid_01] ...

i have parsed everything except for reference

rulesfile: [*rulesid_01] target_list: [*runid_01]
i know many of the fields won't make much sense asking the question but i have edited coz these files are very huge , if still its not very readable pls let me know i will further reduce the number of fields. pls help to solve the reference, i want to know how to write a variable which will be pointing to my run target parameter from my standalone execution.

Replies are listed 'Best First'.
Re: YAML parsing in perl reference decoding
by choroba (Cardinal) on Jul 04, 2016 at 06:52 UTC
    Crossposted to StackOverflow. It's OK to crosspost, but it's considered polite to inform about crossposting to boost cooperation and to save people not attending both sites from unnecessary effort while hacking a problem already solved at the other end of the internet.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: YAML parsing in perl reference decoding
by kroach (Pilgrim) on Jul 03, 2016 at 13:40 UTC
    First, use strict and warnings. What exactly are you trying to accomplish here? It would help greatly if you provided a sample of the structure you want to assemble.

      this is just lifted ( part of main code) , i am facing issues while parsing yaml file ( only in the reference part of it marked in bold). I know to use strict and warnings but this is not entire files.

        ... the ... part of it marked in bold ...

        The *rulesid_01 and *runid_01 links don't go anywhere. Are there supposed to be  [ ] square brackets in this string or around these substrings? Do you perhaps need to use  <code> ... </code> tags? Please see Markup in the Monastery and Writeup Formatting Tips.


        Give a man a fish:  <%-{-{-{-<

Re: YAML parsing in perl reference decoding
by t-rex (Scribe) on Jul 04, 2016 at 10:34 UTC

    i have figured out the solution myself, posting it : code is as follows

    @se_rules_name = (); @se_rules_hostname = (); @se_rules_username = (); @se_rules_password = (); @se_rules_path = (); my $i = 0; for my $rindex (@$se_rulesfile) { $se_rules_name[$i] = $rindex->{name}; $se_rules_hostname[$i] = $rindex->{hostname}; $se_rules_username[$i] = $rindex->{username}; $se_rules_password[$i] = $rindex->{password}; $se_rules_path[$i] = $rindex->{path}; print "$se_rules_hostname[$i],$se_rules_name[$i],$se_rules_us +ername[$i],\n"; $i++; }

    will edit it later in a better way, now have to complete some office work