Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Filehandles

0 views
Skip to first unread message

valerie....@gmail.com

unread,
May 10, 2008, 9:36:10 AM5/10/08
to
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

Ben Bacarisse

unread,
May 10, 2008, 12:41:56 PM5/10/08
to
valerie....@gmail.com writes:

> 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.

--
Ben.

Eric Pozharski

unread,
May 10, 2008, 4:43:25 PM5/10/08
to
valerie....@gmail.com wrote:
*SKIP*
use strict;
use warnings;

> open INPUT, "inputfile";

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

reread L<perlopentut>

> while (<INPUT>) {
> ...

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

> 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.

--
Torvalds' goal for Linux is very simple: World Domination

0 new messages