in reply to Issue with communication of large data between Parent and child using Perl pipes

First, I would always recommend the use of warnings and strict;

What you have here doesn't appear to be a client-server application. For example: $pid=open(PARENT_READ_HANDLE, "-|"); "open()" does NOT return a PID, it returns status code from the open. The open function does not create a PID. For something like this:

open (PROG, "some_program its_args |") or die "can not run some_program $!";
open creates a filehandle status return code! PROG is a filehandle that captures the output of "some_program". You can do: while(<PROG>){...blah...}. This is a synchronous open and is a way of allowing the main program to capture the output of "some_program". Both programs really aren't "running at the same time".

I looked for that the "-" modifier does in front of pipe symbol, eg "-|" instead of just "|" and didn't figure that out. I doubt that the answer changes the above, but would be curious as to what that "-" means...thanks to anybody who can clue me in!

Replies are listed 'Best First'.
Re^2: Issue with communication of large data between Parent and child using Perl pipes
by ikegami (Patriarch) on Jul 17, 2009 at 21:39 UTC

    I looked for that the "-" modifier does in front of pipe symbol,

    It's the 3-arg form of "command|"

    open(my $pipe, "$command |") # 2-arg form open(my $pipe, '-|', $command) # 3-arg form

    "open()" does NOT return a PID

    Actually, it does when using open to create a process and pipe. This is documented.

    And it appears that -| and |- without further arguments simply forks without executing anything instead of giving an error or trying to launch a program named "-". This doesn't seem to be documented. [ Apparently it is, just not in open. See reply ]

      This doesn't seem to be documented.

      It's documented in Safe Pipe Opens, with examples that might be helpful to the OP.

      Thanks! ikegami!

      open(my $pipe, "$command |") # 2-arg form open(my $pipe, '-|', $command) # 3-arg form
      above looks right, this 2 arg form from OP looked weird to me:
      $pid=open(PARENT_READ_HANDLE, "-|");
      Which as they say is neither fish or fowl (not correct 2-arg or 3 arg). I am still a bit confused as to the OP's intent here. This still appears to be a synchronous app, not client-server. There is a lot of complex stuff that doesn't appear to be necessary.