S
shree
I have a data set that looks like this. It basically shows members
added to an organization on a monthly basis.
2007-01|member1
2007-01|member2
2007-01|member3
2007-02|member4
2007-03|member5
2007-03|member6
I wrote the following script to get monthly counts.
#!/usr/bin/perl
my %hash;
my $File_In = "Members.txt";
open (DATA, $File_In) or die "Cannot open File_In $!";
while( <DATA> ){
my($yyyy_mm, $member_name) = split /\|/;
$hash{$yyyy_mm}++;
}
print "yyyy-mm|members added\n";
foreach (sort keys %hash) {
print "$_|$hash{$_}\n";
}
yyyy-mm|members added
2007-01|3
2007-02|1
2007-03|2
Now I'm asked to add 2 more fields in the output. One is running
cumulative total and another is percentage increase over the
preceeding month. I'm not sure how to this and would appreciate any
tips. I have listed a mockup of the results - done in Excel for
illustration.
yyyy-mm|members added|cumulative total|% increase over last month
2007-01|3|3|-
2007-02|1|4|33.33%
2007-03|2|6|50.00%
Thanks,
Shree
added to an organization on a monthly basis.
2007-01|member1
2007-01|member2
2007-01|member3
2007-02|member4
2007-03|member5
2007-03|member6
I wrote the following script to get monthly counts.
#!/usr/bin/perl
my %hash;
my $File_In = "Members.txt";
open (DATA, $File_In) or die "Cannot open File_In $!";
while( <DATA> ){
my($yyyy_mm, $member_name) = split /\|/;
$hash{$yyyy_mm}++;
}
print "yyyy-mm|members added\n";
foreach (sort keys %hash) {
print "$_|$hash{$_}\n";
}
yyyy-mm|members added
2007-01|3
2007-02|1
2007-03|2
Now I'm asked to add 2 more fields in the output. One is running
cumulative total and another is percentage increase over the
preceeding month. I'm not sure how to this and would appreciate any
tips. I have listed a mockup of the results - done in Excel for
illustration.
yyyy-mm|members added|cumulative total|% increase over last month
2007-01|3|3|-
2007-02|1|4|33.33%
2007-03|2|6|50.00%
Thanks,
Shree