Why is my Perl in-place script exiting with a zero exit code even though it's failing?
问题 I have a one-liner Perl search and replace that looks roughly like this: perl -p -i -e 's/foo/bar/' non-existent-file.txt Because the file doesn't exist (which isn't intentional, but this is part of an automated build script, so I want to protect against that), Perl exits with this error: Can't open non-existent-file.txt: No such file or directory. However, the exit code is still zero: echo $? 0 Am I doing something wrong? Should I be modifying my script, or the way I'm invoking Perl? I was