Simple task:
I have a script with line:
qx(wget -P $destination $file) || die "i can't download file: $file!\n";
but every time (if it was success or not), the script dies.
How should i change it to idiom behavior? (success – live, not – die)
Thanks for help!
Some edition:
I want to know all logs, so i prefer to use line such this:
print qx(...)||die"EXPLAIN";
qxis the same as using the backticks operator. It returns the output of the program being executed, but only of its STDOUT, not of STDERR. wget doesn’t seem to be outputting anything on STDOUT (it reports progress on STDERR), hence the result is an empty string which is falsish in the Perl sense — and thedieis called.Normally you don’t evaluate the output of a program in order to determine whether or not it has succeded, but its exit status. That can be done with comparing
$?to 0 as most Unix CLI programs return 0 upon success.If you don’t need the output from wget in the first place then don’t use
qxbutsysteminstead. It returns the program’s exit code directly, allowing you to writedie "oh noes!" if 0 != system("wget ...").