in reply to Carp: $! vs "$!" in croaking
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"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Carp: $! vs "$!" in croaking (updated)
by ikegami (Patriarch) on Jun 26, 2023 at 15:21 UTC | |
by ikegami (Patriarch) on Jun 26, 2023 at 15:50 UTC | |
|
Re^2: Carp: $! vs "$!" in croaking
by cavac (Prior) on Jun 26, 2023 at 09:46 UTC |