Do not try to pass potentially non-existent array elements into
functions since that is going to kill the Perl interpreter.
While here, do not attempt to parse $PATH or $ENV when undefined.

Crash found the hard way with a dubious /root/.login file by otto@ who
declares himself unable to read perl code even though he can apparently
debug it with ktrace(1) - thanks for the excellent bug report!

Feedback and ok florian@.
The Perl close() function, when called on pipe file descriptors,
provides information from wait(2), which needs careful inspection
in order to not hide errors.

Problem identified by florian@ after a bug report from otto@.
Fix based on a patch from florian@, considerably tweaked by me.
OK florian@