Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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!

Re: Filehandles writes:

Quoted text here. Click to load it

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

Quoted text here. Click to load it

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


Re: Filehandles wrote:
    use strict;
    use warnings;

Quoted text here. Click to load it

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

reread L<perlopentut>

Quoted text here. Click to load it

review the code under elipsis with adding C<die>'s for any function that
can fail (rereread L<perlfunc>).

Quoted text here. Click to load it

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

Torvalds' goal for Linux is very simple: World Domination

Site Timeline