in reply to Re: Accumulating Column Total From a CSV for a Common Key Value
in thread Accumulating Column Total From a CSV for a Common Key Value


agianni,


I ran your modified code with the input that I sent
initially. When I run the script I am getting the use
of an uninitialized variable message at the printf
statement.

printf $OUTCSV ("$server,$date,$appl,%3.1f%% \n", $total{$appl});

The $total($appl) must be wrong, as the output is as
follows:
xsd00544,05/2007,PTI - Private Client Services,0.0% xsd00544,05/2007,CTI,0.0% xsd00544,05/2007,OMS,0.0% xsd00544,05/2007,CTI Production ,0.0% xsd00544,05/2007,SSG-RAC-Maestro ,0.0% xsd00544,05/2007,SSG-IPM,0.0% xsd00544,05/2007,Merva,0.0% xsd00544,05/2007,"DB2DARI ""stored procedures"" prod",0.0% xsd00544,05/2007,SSG-PMD-Omegamon,0.0% xsd00544,05/2007,BMW,0.0%

Replies are listed 'Best First'.
Re^3: Accumulating Column Total From a CSV for a Common Key Value
by agianni (Hermit) on Aug 30, 2007 at 13:06 UTC
    Sorry, that was just off the top of my head, not tested. Hopefully you've figured this out on your own already, but just replace $total{$appl} with $total{$server}->{$date}->{$appl} and that should give you the values in the pct column you're looking for. If you didn't figure that out on your own, you should really read up on perl data structures. perldsc is a good place to start.
    perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'

      agianni, this worked marvelously and most importantly I picked up a few pointers on perl use. It now turns out that I have in my input multiple Servers (the 1st field) in addition to multiple Login ID's (the 3rd field) per Application (the 4th field). I am able to accumulate the Percent of Totals by Application with your code.

      Sample output from your code would look as follows:

      xsd00501,05/2007,"Shared Production (PRD,0.2% xsd00501,05/2007,OMX (old MBX userid),0.9% xsd00501,05/2007,PTI - Private Client Services,0.0% xsd00501,05/2007,SSG-IPM,3.1% xsd00501,05/2007,SSG-PMD-Omegamon,0.6% xsd00501,05/2007,SSG-RAC-Maestro ,45.7% xsd00501,05/2007,STW - Stock Transfer Workstation,1.1% xsd00506,05/2007,ADR,0.4% xsd00506,05/2007,OBR Production,0.1% xsd00506,05/2007,RAC/AMOS/DSO,43.3% xsd00506,05/2007,SPS - Inform,1.2% xsd00506,05/2007,SPS Production (also IRD till 7/03),11.7% xsd00506,05/2007,SSG-IPM,2.6% xsd00506,05/2007,SSG-PMD-Omegamon,0.6% xsd00506,05/2007,SSG-RAC-Maestro ,17.0% xsd00544,05/2007,"DB2DARI ""stored procedures"" prod",2.1% xsd00544,05/2007,BMW,0.0% xsd00544,05/2007,CTI Production ,21.7% xsd00544,05/2007,CTI,13.1% xsd00544,05/2007,Merva,0.0% xsd00544,05/2007,OMS,13.7% xsd00544,05/2007,PTI - Private Client Services,0.0% xsd00544,05/2007,SSG-IPM,4.5% xsd00544,05/2007,SSG-PMD-Omegamon,0.1% xsd00544,05/2007,SSG-RAC-Maestro ,2.6% xsd00722,05/2007,SSG-PMD-Omegamon,1.9% xsd00722,05/2007,SSG-RAC-Maestro ,23.1%

      In addition, after the last Server entry, I need to output a TOTAL line with the Total Percentage for all Applications for a particular Server and Date. For the server/date combination (xsd00501,05/2007) above, a line after the last line with xsd00501,05/2007, would be printed totalling the percentages, as follows:

      xsd00501,05/2007,TOTAL,51.6%

      Up to this point in my limited perl programming experiences,I have been unable to grasp how to determine when a particular variable changes its value in the input and when this happens doing a particular task.

      Any assistance would be greatly appreciated.