It seems this does the same thing as open my $fh_echo, "-|", "$sshstr \"$str\""
. It deparses as:
exec qq[$sexec qq[$sshstr "$str"] unless open my $fh_echo, '-|'
The output isn't really loaded into $fh_echo when things are opened successfully, $fh_echo becomes a filehandle with the output of the executable in the right-most argument of open() by way of a pipeline. For more on pipelines, check out the wikipedia page. It should be pointed out that your given example, however, doesn't open anything. Because there is no command on the right-hand side of the example you provided, open() will always return a non-true value indicating failure, and the right side of the expression will always run. See http://ideone.com/wupJ8
To go into further details if it were to be successful, we'll use open my $f, "-|", "echo hi"
as a better example. What this does is redefine stdin on for the child process as being the right side of a pipe, making it roughly equivalent to the following:
pipe my $fh_echo, my $childout;
if (fork == 0) {
close STDOUT;
open STDOUT, ">>&", $childout;
exec "echo hi";
}
This first creates a pipe, and then forks. In the child process, stdout is redefined as the write side of the pipe. exec
is then called (see exec(2) for more details) which replaces the current process with the given process. From that point on, since stdout has been redefined as being the writable side of the pipe, all output to stdout will actually write to the pipe instead of what-ever the target might have been before.
Also, to go into further detail on exec "echo hi" defects to a shell since it's not a fully qualified executable path. Which is to say, it actually gets read by perl as exec "/bin/sh", "echo hi"
since perl decides to make no decisions as to what the given expression might really mean.
Hopefully that explains the mechanics.