steelcarn99 has asked for the wisdom of the Perl Monks concerning the following question:

Within my main perl program (which is on my local machine)I am calling another perl program that runs on a remote machine that I have made an SSH connection to. Is there anyway to use the variables from the remote program in the original program on my local machine? Or perhaps capture the STDOUT since I'm getting all print commands returned to my local machine. Any help would be appreciated. Thanks for your time.
  • Comment on sending variables between .pl over remote machines

Replies are listed 'Best First'.
Re: sending variables between .pl over remote machines
by Bloodnok (Vicar) on Aug 11, 2009 at 13:30 UTC
    1. Have the remote script update a hash with the variable name and its value
    2. Use Data::Dumper to dump the hash to STDOUT
    3. Capture STDOUT from the remote m/c (as you're already doing)
    4. eval the captured text (Data::Dumper output) to locally recreate a hash
    ???

    A user level that continues to overstate my experience :-))
      How do you go about capturing the STDOUT?

      (In my remote script)

      print $lastrecord;

      This gets printed to the command line on my local machine. Is there a special variable that I can call that holds this value?
        A few more details would help, but I'm assuming your local script has something along the lines of `ssh $remote_host $cmd`;, if so, then modifying this to read my $out = `ssh $remote_host $cmd`;` will capture STDOUT, from the remote host, into $out.

        Subsequently, assuming a hash was dumped at the remote host, eval $out;die $@ if $@; should create $VAR1 as a hash ref. locally.

        A user level that continues to overstate my experience :-))