in reply to Using latest code

You can use system to call another program. As for the version thing, the (imho) easiest way would be to store the actual version number of each "other program" somewhere on disk and read that info upon each request. Store the programs in a "version_number/program" structure and construct the call path accordingly.


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Using latest code
by drake50 (Pilgrim) on Sep 02, 2007 at 05:56 UTC
    I thought about using a system call but how can I handle passing the socket connection as-is? The operator or switchboard program has already established a connection with the user and validated them. I'd like to hand off this connection to another program to then handle the rest of the actions.
      Well, that brings a new problem into play.
      Honestly, I have no idea how to share an already opened socket via system. I think I would just put the "establishing and validating" code into a module and use that from the versioned scripts.


      holli, /regexed monk/

      Ever heard of inetd? Or NPH CGI? It is quite easy to pass an open socket to a child process.

      The way to do that with system (avoids fork amd exec and so is more portable) is simply to dup the socket to be STDIN and/or STDOUT (file descriptors 0 and/or 1, since file handles don't get inherited).

      Use the sample code in open if you want to save then restore your existing STDIN/STDOUT, then just do:

      # (save STDIN/STDOUT here) open STDIN, "<&".fileno(*SOCK) or die "Can't dup SOCK to STDIN: $!$/"; open STDOUT, ">&".fileno(*SOCK) or die "Can't dup SOCK to STDOUT: $!$/"; system( ... ) and ...; # (restore STDIN/STDOUT here)

      Perl is smart enough to ensure that STDIN remains fd 0 and STDOUT remains fd 1 for the above.

      - tye