in reply to Passing a filehandle from C to perl

It can be done, but I've found tricks like this to be error-prone and non-portable in the past. You're much better off passing the file name instead, and let each program open its own descriptor. That said, here's what you can do, presuming you're on something unix-like.

Your C program has to use a file descriptor not used by the shell; let's say you use lucky seven:

int fd = open("/some/file", O_RDWR); dup2(fd, 7); close(fd);
Of course, you need to test that all the calls succeed.

With that, you can take advantage of the fact that fork will take along open file descriptors:

int pid = fork(); if (pid == 0) { execl("/the/perl/program", "program", "arg1", "etc"); _exit("URK!"); } close(7);
Again with tests inserted appropriate places.

In the Perl program, you take advantage of funny syntax in open being equivalent to a C fdopen, as documented in perlfunc:

open FH, '+<=7'; my $line = <FH>; # or whatever
This presumes the C program and the Perl program agree on file descriptor 7 being the "magic" one.

Note, I haven't tested this code; takes way too long to set up a reasonable test....