我需要在$!中从sub返回错误文本.但很简单
$! = "Error: Something is wrong!";
Run Code Online (Sandbox Code Playgroud)
不起作用,它不会改变$!我该怎么做?
$!是C库var errno(一个数字)的反映和它所代表的错误消息(使用strerror或类似获得).
您无法更改字符串,因为这是生成的值,但您可以更改该数字.
$ perl -E'say $!=$_ for 1..10'
Operation not permitted
No such file or directory
No such process
Interrupted system call
Input/output error
No such device or address
Argument list too long
Exec format error
Bad file descriptor
No child processes
Run Code Online (Sandbox Code Playgroud)
你的代码没有尝试设置errno,所以它应该使用自己的变量而不是搞乱$!(或使用异常die).
| 归档时间: |
|
| 查看次数: |
183 次 |
| 最近记录: |