Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1075262]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2018-03-18 18:22 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (230 votes). Check out past polls.