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";
}
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";
}