$stock_current{$inventory_item->{'inventory_item_id'}} = $inve
+ntory_item->{'starting_quant'};
$stock_minimum{$inventory_item->{'inventory_item_id'}} = $inve
+ntory_item->{'starting_quant'};
Put $inventory_item->{'inventory_item_id'} and $inventory_item->{'starting_quant'} in a lexical scalar ref or copy the string to a lexical. Hash lookups are expensive and multiple lookups can not optimized away (what if its a tied hash where every fetch changed the key's value?).
$stock_current{$stock_change_data_ref->{'inventory_item_id'}}
++= $stock_change_data_ref->{'Qty_Change'};
if ($stock_current{$stock_change_data_ref->{'inventory_item_id
+'}} < $stock_minimum{$stock_change_data_ref->{'inventory_item_id'}}){
$stock_minimum{$stock_change_data_ref->{'inventory_item_id
+'}} = $stock_current{$stock_change_data_ref->{'inventory_item_id'}};
}
Stop fetching $stock_change_data_ref->{'inventory_item_id'} 5 times. See above notes. Also note there searching and sorting algorithms that may help you. A CS nerd can help you with those more than me.
foreach(@inventory_items_array){
$_->{'rem_avail_quant'} = $stock_minimum{$_->{'inventory_item_
+id'}};
$_->{'available'} = $_->{'rem_avail_quant'} . '/' . $_->{'inv_
+quant'};
It looks to me like this loop can be merged with the "while ($stock_change_data_ref = $stock_change_sth->fetchrow_hashre
f()){" but I am not sure.