I am struggling with a problem. I have a hash, example:
$myHash{$customer}{money}The $customer is a value that I get by analizing a database everyday. This means, that everytime I run the script, there might be a new customer. The result of the hash is a scalar (money they spent).
I want to write a procedure how to extract the money they spent, by each $customer. I tried somehow like this:
foreach $customer (keys %myHash){ $money_spent = $myHash{$customer}{money}; }
Ofcourse, I am aware this doesnt work as i want, because the $money_spent will change everytime another $customer comes.
But I don't know how to get it done efficiently. I DO NOT WANT TO USE IF STATEMENTS HERE, LIKE THIS:
foreach $customer (keys %myHash){ print "$customer \n"; #--check what customers are there if ($customer eq 'NAME-OF-CUST'){ $money_spent_name_of_cust = $myHash{$customer}{money}; } ... }
I dont want to manually write down an IF statement for every $customer. There has to be a way, to store the values for each customer into a variable $money_spent.
Ideas very appreciated. DavidIn reply to Keys and Values from Hash by David92
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |