Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^7: (OT) Perl and creating a query for MongoDB

by poj (Abbot)
on Aug 01, 2019 at 14:56 UTC ( [id://11103714]=note: print w/replies, xml ) Need Help??


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

Can you post the perl script and source data files that you used to create the report shown on you original post ? i.e.

{ "name": "test1", "all_data": [ { "sub_data": [ { "sub_name": "Test1", "sub_path": "GROUP1/Test1", "info": [ { "group": "pkgs", "values": [ "tcsh" ] }, { "group": "tcsh", "values": [ "6.13.00" ] } ] }, { "sub_name": "GROUP2", "sub_path": "GROUP2", "info": [ { "group": "pkgs", "values": [ "tcsh" ] }, { "group": "tcsh", "values": [ "6.13.00" ] } ] }, ], "all_data_name": "ROOT", "all_data_path": "/PATH/TO/ROOT" } ], "username": "erwerwcsd", "timestamp": "1564475903" }
poj

Replies are listed 'Best First'.
Re^8: (OT) Perl and creating a query for MongoDB
by ovedpo15 (Pilgrim) on Aug 02, 2019 at 19:12 UTC
    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.

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11103714]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-19 07:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found