Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Optimizing Loop

by bulk88 (Priest)
on Feb 18, 2014 at 05:26 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-29 01:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found