At work, we encountered an error when interacting with child processes in the object's destructor and, ultimately, traced it to $? the variable will be overwritten during wait calls. This happens after calling exit (), so $? additionally means that our return code to the operating system.
In particular, perldoc talked about this error:
Inside the END $ routine? contains the value that will be returned by exit (). Can you change $? in the END routine, change the exit status of your program.
We do not want this to happen, so we put local $?=$?; inside each END block. But now programs return the success of the OS, without actually coping with their task.
I managed to break it into two test programs. One that works as intended, and one that fails. This happens on both v5.8.8 and v5.10.1 for x86_64-linux-thread-multi
Program A: (returns 0 to the operating system)
END{ local $?=$?; } exit(100);
Program B: (returns 100 to the operating system)
END{ local $?=$?>>8; } exit(100);
Why does it matter what value was assigned to local $? in the final block?
source share