There is nothing wrong with your code. All you really have to add total_revenue processing is to declare $total_revenue outside the loop and add to it inside the loop. However, you can simplify the logic by using
stevieb's hash suggestion.
>type htmanning2.pl
use strict;
use warnings;
my @hash_rows = (
{total => 3, other_col => 'fie'},
{total => 6, other_col => 'fum'},
{total => 5, other_col => 'oop'},
);
my %revenues = (
3 => 30,
6 => 48,
10 => 50,
);
my $total_revenue;
foreach my $pointer (@hash_rows) { # simulate fetchrow_hashref for po
+st
my $total = $pointer->{total};
next if (!defined $total or !exists $revenues{$total});
my $revenue = $revenues{$total};
$total_revenue += $revenue;
print "revenue: $revenue\ntotal_revenue $total_revenue\n\n";
}
>perl htmanning2.pl
revenue: 30
total_revenue 30
revenue: 48
total_revenue 78
>