I am trying to write code to add up revenue on sales based on the month of a particular year and output total per month per year, something with my code is wrong though and I am just stuck now.
use strict;
use warnings;
my @newPlans = `cat plansSold.txt`;
my @oldPlans = `cat plansCancelled.txt`;
my %amounts;
for(@newPlans){
chomp;
my ($price,$billPeriod,$date) = (split /\;/, $_ )[4,5,7];
my $montly = $price/$billPeriod;
my ($f,$l) = (split /\-/, $date)[0,1];
$montly = (split /\./, $montly)[0];
$date = "$f\-$l";
$amounts{$date} += $montly;
}
for my $date (sort keys %amounts) {
print '.';
print "$amounts{$date} : $_\n" for (sort keys %{ $amounts{$date} });
}
$price,$billPeriod,$date Are as below.
7.95,1,2012-04
9.95,1,2012-06
19.95,12,2012-06
19.95,1,2014-02
12.95,3,2013-03
19.95,1,2014-01
18.95,1,2012-12
18.95,6,2012-12
18.95,1,2012-05
And the error:
Can't use string ("6177") as a HASH ref while "strict refs" in use at revenueHistory.pl line 28.
Whis is this line
for my $date (sort keys %amounts) {
I cant seem to figure out how to fix it.