• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

perl IPC question

puffff

Platinum Member
I have a perl script, it basically prints 1 to 10, one number a second.

I want to have a second script read the output, square it, and print the squared value. Since this second script is reading the initial values once per second, it should print the squares once per second.

I feel like I should be able to do this with open() or something... but the second script won't print anything until the first script finishes running.. I'd like them to run side by side... can anyone help?

First script (a.pl):
for ($i=0; $i <= 10; $i++) {

print STDOUT "$i\n";
sleep(1);

}


Second script (b.pl):

open(RDR, "/tmp/a.pl |");

while (<RDR>) {

print $_ * $_, "\n";

}
 
Yep, output in perl doesn't get flushed to the screen immediately unless you tell it to! I remember it certainly caused me some headaches when I first started perl.
 
Back
Top