http://www.perlmonks.org?node_id=551744


in reply to Returning Error Codes

The Perly solution is to exploit the hash capability of the *@ glob -- it is a well-kept secret. You don't want the function to set a scalar or set an array. You want the function to set the 0 key of a hash -- it is easier to test the return value that way.

(Those who answered with die(), with 'best practices', or even with 'common practices' are avoiding to answer directly the poster's question.)

foo(); $@{0} ? print "error: $@{0}" : print 'ok'; sub foo { $@{0} = 'proxy error' }