One of the first things Carp does is local($!, $^E), I assume because of what its documentation says: "Carp takes care not to clobber the status variables $! and $^E in the course of assembling its error messages." I think what's going on is that since @_ are aliases, this actually clears out the argument as well. Another thing to note is that $! is like a dualvar, though I'm not sure if this has to do with the issue. <update> Actually, in the following, $? behaves the same way as $!, while $@, an our variable, and an explicitly created dualvar do not - so it probably does have to do with the variable's magic in combination with local instead. </update> I suspect you'll have to work with "$!". This reproduces the issue:
use warnings; use strict; use Data::Dump; sub foo { dd @_; local $!; dd @_; } $! = 2; foo($!); $! = 2; foo("$!"); __END__ "No such file or directory" "" "No such file or directory" "No such file or directory"
In reply to Re: Carp: $! vs "$!" in croaking (updated)
by haukex
in thread Carp: $! vs "$!" in croaking
by cavac
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |