#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw( sum0 );
my $hashref =
{
"153-1" => {
"1069-9" => {},
"135-1" => { "68-4" => { cost => "300.00", cost2 => "130.00" }
+},
"19-4" => { cost => "6300.00", cost2 => "630.00" },
"35-1" => { "28-4" => { cost => "30.00", cost2 => "10.00" } },
},
};
print costof( $hashref ), " is the total where cost is found\n";
sub costof
{
my $href = shift;
sum0 map /cost/ ? $href->{$_} : costof( $href->{$_} ), keys %$href;
}
Outputs:
7400 is the total where cost is found