I am not sure whether this is even a perl question. There would be lot of cases where you want to do a couple of operations on a set of objects( say n objects). Some of the operations may be time consuming and may cause huge performance problems when they are done n times. In order to optimize the code we may rewrite it such that we can loop through the objects and then do some operations once on all objects at once shot instead of doing them n times. This could make it faster. For eg. let's say when we want to generate a lot of rows in a report. We call a method report_row on all objects
sub report_row { my $object = shift; $object->op1(); $object->op2(); # op2 is very slow $object->op3(); } report_row($_) for ( @objects );
For optimizing, you may rewrite the code in such a way that
$_->op1() for ( @objects ); # bulk_op2 does the same job as op2 but with all objects in # one shot bulk_op2(@objects); $_->op3() 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?

In reply to Any framework for bulk operations? by ganeshk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.