Filehandles

V

valerie.seigneur

Hi,

I have a question about filehandles, even after reading the docs... I
know how to start a subprocess from perl and read from it. But how do
I write to the parent process that started me, the perl script?

I have tcl script from somewhere that calls a perl script I'm writing.
The tcl script says:
set channel [open |./randomize RDONLY]
It calls the perl script "randomize" which reads from a file, does
things to the content and should make it available for reading from
the tcl script. But how do I do that? Somehow I keep on getting
messages that the input is empty when I run the tcl script.

This would be what "randomize" looks like:
open INPUT, "inputfile";
while (<INPUT>) {
...
print $result;
# I've tried all sorts of things here with | < > at the beginning
or the end,
# exec and backticks...
}

I'd be greatful for any leads on this!
Val
 
B

Ben Bacarisse

I have a question about filehandles, even after reading the docs... I
know how to start a subprocess from perl and read from it. But how do
I write to the parent process that started me, the perl script?

I have tcl script from somewhere that calls a perl script I'm writing.
The tcl script says:
set channel [open |./randomize RDONLY]
It calls the perl script "randomize" which reads from a file, does
things to the content and should make it available for reading from
the tcl script. But how do I do that? Somehow I keep on getting
messages that the input is empty when I run the tcl script.

You have a TCL problem, not a Perl one. If I duplicate what you have
above, I can read from the output of a Perl script just fine. All it
(the Perl part) needs to do is generate output on the standard output
stream (and you may need to flush the stream, but I doubt it from the
context).
This would be what "randomize" looks like:
open INPUT, "inputfile";
while (<INPUT>) {
...
print $result;
# I've tried all sorts of things here with | < > at the beginning
or the end,
# exec and backticks...

That is fine. No |, <, or > needed. No backticks or exec. Just print
and TCL can read it in.
 
E

Eric Pozharski

(e-mail address removed) wrote:
*SKIP*
use strict;
use warnings;
open INPUT, "inputfile";

open my $INPUT, '<', 'inputfile' or
die "can't open inputfile: $!";

reread L said:
while (<INPUT>) {
...

review the code under elipsis with adding C<die>'s for any function that
can fail (rereread L said:
print $result;
# I've tried all sorts of things here with | < > at the beginning
or the end,
# exec and backticks...
}

run B<randomize> at shell prompt, use debagger, post minimal example,
get some life, blah-blah-blah... Perl is fun, have a nice day.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top