ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activeperl
activeperl
Re: Buffering piped output of a script to another script...
by Bill Luebkert other posts by this author
Aug 27 2008 5:47PM messages near this date
Buffering piped output of a script to another script... | kill 0 doesn't work?
Brett.Carroll@[...].gov wrote:
>  
>  Is it possible to buffer the data coming in ($_) based on size rather 
>  than waiting for a newline?
>  
>  Here is a test scenario:
>  
>  #script1.pl
>  while(1){
>  print "Sent: " . localtime() . "\n";
>  }

$| = 1;
while (1) {
	print "Sent: " . localtime ();
	sleep 1;
}

>  ------------------------------
>  
>  #script2.pl:
>  print "Received: $_";

This might work for you, but you really need to know where to put the
newlines other than checking for Sent:

print "Received: ";
while (1) {
	my $buf;
	sysread STDIN, $buf, 128;
	print $buf;
	print "\nReceived: " if $buf =~ /^Sent/;
}

>  Running the above scripts using: "perl script1.pl | perl -n script2.pl" 
>  works fine (as expected).  However I wonder if it is possible to remove 
>  the "\n" from the print statement in script1.pl and let script2.pl 
>  handle the buffering, by this I mean process the print "Received: $_"; 
>  line only when $_ contains x number of characters, bytes, etc...
>  
>  Note: Target platform is Win32.
_______________________________________________
ActivePerl mailing list
ActivePerl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Brett Carroll
Bill Luebkert

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved