in reply to Re^2: Set env variables as part of a command
in thread Set env variables as part of a command

Ok so yeah googled, learned what fork does. Let me ask another probably basic question I could not find in some googling. When I fork the program I execute I need to create an array. I need to return that array to the parent process. How would one do that?
  • Comment on Re^3: Set env variables as part of a command

Replies are listed 'Best First'.
Re^4: Set env variables as part of a command
by afoken (Chancellor) on Feb 18, 2017 at 18:19 UTC
    When I fork the program I execute I need to create an array. I need to return that array to the parent process. How would one do that?

    By serialising and unserialising. Create the array in the child process, write it to a file handle of a pipe, and read that pipe in the parent process. Perl wraps that in open('-|') / open('|-') See perlipc, especially section "Safe Pipe Opens". For simple arrays of simple strings not containing control characters, writing each string on a new line might be sufficient. Otherwise, use Storable, JSON, XML, YAML or something like that.

    Update: You might need to fork once again from your first child to be able to "return" an array after the external program has finished.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)