[tpm] Writing to STDOUT in batches

Indy Singh indy at indigostar.com
Mon Dec 6 07:41:15 PST 2010


The followig code works for me:

open (OUT, "|sed -n '1,2p'");
print OUT "Line 1\n";
print OUT "Line 2\n";
print OUT "Line 3\n";
close OUT;

This will print out just the first 2 lines and not the third.

Indy Singh
IndigoSTAR Software -- www.indigostar.com

  ----- Original Message ----- 
  From: Antonio Sun 
  To: TPM Mongers 
  Sent: Monday, December 06, 2010 10:22 AM
  Subject: [tpm] Writing to STDOUT in batches


  Hi, 


  I have the following code in a loop:


      open(OUTFILE, "$cmd >> myfile"); # append write 
     print OUTFILE content();
     close(OUTFILE);


  The $cmd is a complicated sed command. For simplicity purpose, let's say it is 


    | sed -n '10,20p' 


  I.e., printing only lines 10~20 of the content of each loop. 


  My goal is to write to STDOUT instead of a fixed file. I tried to change the above open statement with


     open(OUTFILE, "$cmd >-");   # write to STDOUT


  or,


     open(OUTFILE, "$cmd >>-");   # write to STDOUT


  but didn't get any output. 


  Anyone can help me here? 


  BTW, in case you wonder why the open statement is in the loop -- if I don't do it this way and open outside the loop instead, I'll  get the first 10~20 lines only from the first loop.


  Thanks


  antonio






------------------------------------------------------------------------------


  _______________________________________________
  toronto-pm mailing list
  toronto-pm at pm.org
  http://mail.pm.org/mailman/listinfo/toronto-pm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20101206/a8e65d6f/attachment.html>


More information about the toronto-pm mailing list