Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Optimizing Loop

by bulk88 (Priest)
on Feb 18, 2014 at 05:26 UTC ( #1075262=note: print w/ replies, xml ) Need Help??


in reply to Optimizing Loop

$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.


Comment on Re: Optimizing Loop
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1075262]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-10-22 06:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (114 votes), past polls