[tpm] Writing to STDOUT in batches

Richard Dice rdice at pobox.com
Mon Dec 6 08:03:37 PST 2010

> The reason why I need the open statement is in the loop -- I need to print
> a selected portion of the content **of each loop**. If I don't do it this
> way and open outside the loop instead, I'll get the portion only from the
> first loop.
> Think of double loop here, where content() maybe the foreach loop that you
> gave.
That doesn't seem to be a problem to me, given my understanding of what you

Imagine content() takes a parameter $i, and returns a list of lines, which
you want the 10-20 range of lines printed to STDOUT.  (It takes $i as a
param just so that any given run of content() isn't the same, let's say.)

foreach my $i ( 'a' .. 'z' ) {
    open TEST "|sed -n '10,20p'";
    print TEST content($i);
    close TEST;
} # foreach

So now each time you call content you'll print lines 10-20 of its return
value to STDOUT.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20101206/63535ccf/attachment.html>

More information about the toronto-pm mailing list