I want to return a different value in string context and numeric context like $! does. I know I can find out whether I am in list or scalar context with wantarray, but is there any way in pure Perl to determine which scalar context I am in? I assume there is an answer in XS as well and I am willing to take that answer if there is no way do it in pure Perl.
I want to return a different value in string context and numeric context like
Share
Check out the
Scalar::Utilmodule, specifically thedualvar()function:Scalar::Utilis part of the core distribution, and should be avaliable anywhere you have Perl.