cavac has asked for the wisdom of the Perl Monks concerning the following question:
I run into a strange thing in how croak() (from the Carp module) works:
#!/usr/bin/env perl use v5.36; use strict; use warnings; use Carp; open(my $ifh, '<', 'doesnotexist.dat') or croak($!);
This outputs:
at carptest2.pl line 9.
But when i change croak($!) to croak("$!"), everything works as expected:
No such file or directory at carptest2.pl line 9.
Shouldn't that result in the exact same output with both variants? It certainly does so with the builtin die(), where both die($!) and die("$!") print:
No such file or directory at carptest2.pl line 9.
Do i have a basic misunderstanding on how $! works/should work or is this a bug (or workaround) with Carp?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Carp: $! vs "$!" in croaking
by Corion (Patriarch) on Jun 26, 2023 at 09:26 UTC | |
|
Re: Carp: $! vs "$!" in croaking (updated)
by haukex (Archbishop) on Jun 26, 2023 at 09:27 UTC | |
by ikegami (Patriarch) on Jun 26, 2023 at 15:21 UTC | |
by ikegami (Patriarch) on Jun 26, 2023 at 15:50 UTC | |
by cavac (Prior) on Jun 26, 2023 at 09:46 UTC | |
|
Re: Carp: $! vs "$!" in croaking
by haj (Vicar) on Jun 26, 2023 at 10:54 UTC |