in reply to Re: Timing out ``?
in thread Timing out ``?

Side note: I don't think @list = `ssh machine "ls path"`; does what you think it does; maybe you mean @list = split /\n/, `ssh machine "ls path"`;?

Yes it does:

In scalar context, it comes back as a single (potentially multi-line) string, or undef if the command failed. In list context, returns a list of lines (however you've defined lines with $/ or $INPUT_RECORD_SEPARATOR), or an empty list if the command failed.
perlop

So while the OP's way is safe, you'd even have to check for undef before splitting to avoid warnings on failure---which will even be fairly frequent in his use case.

Replies are listed 'Best First'.
Re^3: Timing out ``?
by kennethk (Abbot) on Jun 07, 2012 at 00:05 UTC
    Except that all of your list entries will have trailing newlines (see perl -e '@list = `ls`; print $list[0] =~ /\n/ ? "yes\n" : "no\n"') which can cause funny errors depending on how you use the list. I would actually consider a warning on failure to be a good thing in this case, although the emitted warning would be unfortunately ambiguous. But this is all fairly subjective, particularly without seeing how the list gets used.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.