ganeshk has asked for the wisdom of the Perl Monks concerning the following question:
For optimizing, you may rewrite the code in such a way thatsub report_row { my $object = shift; $object->op1(); $object->op2(); # op2 is very slow $object->op3(); } report_row($_) for ( @objects );
An example where this situation can arise is suppose you do some database query to get some data using some object attribute. Doing it on all objects would require n query executions. You may convert the query to support n attributes and then execute the query in one shot for all objects. But I feel that the initial code is much more readable than the latter. Now is there any framework or pattern using which we can still have the code as the first kind(or atleast close to the first) and still make it work like the second. Is it possible to express in any way that some operation can be done on bulk?$_->op1() for ( @objects ); # bulk_op2 does the same job as op2 but with all objects in # one shot bulk_op2(@objects); $_->op3() for ( @objects );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Any framework for bulk operations?
by dragonchild (Archbishop) on May 16, 2008 at 17:11 UTC | |
by ganeshk (Monk) on May 16, 2008 at 17:59 UTC | |
by dragonchild (Archbishop) on May 16, 2008 at 18:11 UTC | |
|
Re: Any framework for bulk operations?
by BrowserUk (Patriarch) on May 16, 2008 at 18:18 UTC |