in reply to Re^7: (OT) Perl and creating a query for MongoDB
in thread (OT) Perl and creating a query for MongoDB

It looks like something like this (removed the checks):
my $number_of_mains = 0; my $number_of_subs = 0; foreach my $main (sort(uniq(@mains_paths))) { my (@list_of_dirs,@subs_data); my $main_path = abs_path($main); find( sub { get_valid_dirs( \@list_of_dirs, $_ ) }, $main_path); my $main_name = basename($main_path); my %main_block = ( $ALL_DATA_NAME => $main_name, $ALL_DATA_PATH => $main_path ); $number_of_mains++; foreach my $dir (sort(@list_of_dirs)) { my ($sub_path,$sub_name,$relative_sub_path,$paths_all,$results +_all,@results_data,%sub_block); $sub_path = dirname($dir); $sub_name = basename($sub_path); $relative_sub_path = File::Spec->abs2rel($sub_path,$main_path) +; %sub_block = ( $SUB_NAME => $sub_name, $SUB_PATH => $relative_sub_path, ); $results_all = $dir."/".$DIR_NAME."/".$RESULTS_FILE_NAME; unless((-e $results_all) && (-s $results_all)) { next; } prase_file($results_all,\@results_data); $number_of_subs++; @{$sub_block{$RESULTS}} = @results_data; push(@subs_data,\%sub_block); } @{$main_block{$SUBS}} = @subs_data; push(@mains_data,\%main_block); } @{$all_mains{$MAIN}} = @mains_data; $all_mains{$REPORT_NAME} = $opt_href->{$REPORT_NAME}; $all_mains{$MAIN_COUNTER} = $number_of_mains + 0; $all_mains{$SUBS_COUNTER} = $number_of_subs + 0; $all_mains{$TIMESTAMP} = $start_time + 0;
I'm trying now to understand how to do the opposite thing.

Replies are listed 'Best First'.
Re^9: (OT) Perl and creating a query for MongoDB
by poj (Abbot) on Aug 02, 2019 at 20:31 UTC

    What is the code in the prase_file() subroutine ?

    poj
      code:
      sub prase_results { my ($file_path,$aref) = @_; open(my $fh, '<', "$file_path") or return 0; while (my $line = <$fh>) { chomp($line); my ($key,$group,$value,$version,$file,$count) = split(/,/,$lin +e); my $key = 1; foreach my $k (@{$aref}) { if ($k->{"group"} eq $group) { $k->{"version"} = [ sort uniq $version, @{$k->{"version"}} ]; $key = 0; } } push @{ $aref }, { group => $group, versions => [ $version ] } if ($key); } close ($fh); return 1; }
      By the way, I opened a new thread so it will be clear and clean. Thank you for the help.
        it will be clear ..

        It's not clear to me how this code

        foreach my $k (@{$aref}) { if ($k->{"group"} eq $group) { $k->{"version"} = [ sort uniq $version, @{$k->{"version"}} ]; $key = 0; } } push @{ $aref }, { group => $group, versions => [ $version ] } if ($key);

        can create this data structure

        { "group": "pkgs", "values": [ "tcsh" ] },

        Is the key 'version', 'versions' or 'values' ?

        poj