http://qs321.pair.com?node_id=1232873


in reply to TOTAL Element understanding - Why and how to use this?

At a first glance it looks like the code is doing some counting and is doing sums by certain categories. Highest level is by app, then by device, then by browser. Wherever you see 'TOTAL' in a particular column, it means that the distinction between different devices, say, is ignored, and a total across all devices is done. Same for app and browser.

  • Comment on Re: TOTAL Element understanding - Why and how to use this?

Replies are listed 'Best First'.
Re^2: TOTAL Element understanding - Why and how to use this?
by chandantul (Scribe) on Apr 23, 2019 at 01:16 UTC

    Thanks for your responses! I would like to understand more in details, If you are telling highest is app label ( CGA,HGS,YAG, TAG) then device label (Computer,Mobie) then browser label (IE11,CHROME,EDGE), In the loop, its checking the counts for %pivot hash by $pivot{$app}{$device}{$browser}; ? Can you please elaborate the difference between following code snippet about which sum its doing ++$pivot{$app}{'TOTAL'}{$browser}; ( is this counting total app counts and what about the browser here? Please let me know about this too ++$pivot{$app}{'TOTAL'}{'TOTAL'}; Please check entire for loop

    for ($k = 0; $k <= $#responseid; $k++) { next if ($responseclientbrowser[$k] =~ /IE7/i); $worksheet1->write($row1,0, $responseid[$k],$format2); $worksheet1->write($row1,1, $responsdisp[$k],$format2); $worksheet1->write($row1,2, $responsalter[$k],$format2); $worksheet1->write($row1,3, $responseclientdevice[$k],$format2 +); $worksheet1->write($row1,4, $responseclientbrowser[$k],$format +2); $worksheet1->write($row1,5, $responseapps5[$k],$format2); $worksheet1->write($row1,6, $estdate[$k],$format2); $app = $responseapps5[$k]; $device = $responseclientdevice[$k]; $browser = $responseclientbrowser[$k]; $userid = $responseid[$k]; #print Dumper $browser; ++$pivot{$app}{$device}{$browser}; #print Dumper ++$pivot{$app}{$device}{$browser}; ++$pivot{$app}{'TOTAL'}{$browser}; # print Dumper ++$pivot{$app}{'TOTAL'}{$browser}; ++$pivot{$app}{'TOTAL'}{'TOTAL'}; #print Dumper $pivot{$app}{'TOTAL'}{'TOTAL'}; ++$pivot{$app}{$device}{'TOTAL'}; ++$pivot{'TOTAL'}{$device}{$browser}; #print Dumper $pivot{'TOTAL'}{$device}{$browser}; #++$pivot{$app}{$browser}; ++$categ{'device'}{$device}; ++$categ{'browser'}{$browser}; ++$app{$app}; $row1++; #print Dumper $app; }

      I have replaced the 'TOTAL' with a more "speaking" label. Pls look at the 'all...' rows and how they represent the sums of the (random) data in each of the blocks:

      use strict; use warnings; use Data::Dumper; my %pivot; # generate 100 random records for app(lications) being accessed thru s +ome dev(ices) with some bro(wsers) for(1..100){ my($app,$dev,$bro) = (qw(App1 App2 App3)[rand 3],qw(Dev1 Dev2 Dev3 +)[rand 3],qw(Bro1 Bro2 Bro3)[rand 3]); ++$pivot{$app}{$dev}{$bro}; ++$pivot{'allapps'}{$dev}{$bro}; ++$pivot{$app}{'alldevs'}{$bro}; ++$pivot{$app}{$dev}{'allbros'}; ++$pivot{'allapps'}{'alldevs'}{$bro}; ++$pivot{$app}{'alldevs'}{'allbros'}; ++$pivot{'allapps'}{$dev}{'allbros'}; ++$pivot{'allapps'}{'alldevs'}{'allbros'}; } # statistics for accesses for my $app (sort keys %pivot) { for my $dev (sort keys %{$pivot{$app}}) { for my $bro (sort keys %{$pivot{$app}{$dev}}) { print "$app\t$dev\t$bro\t$pivot{$app}{$dev}{$bro}\n"; } print "------------------------------------------------\n"; } }