我想检测一个子程序是如何被调用的,所以我可以根据每种情况使它的行为不同:
# If it is equaled to a variable,do something: $var = my_subroutine(); # But if it's not,do something else: my_subroutine();
那可能吗?
解决方法
使用
wantarray
if(not defined wantarray) { # void context: foo() } elsif(not wantarray) { # scalar context: $x = foo() } else { # list context: @x = foo() }