Re^2: Should I use carp/croak or warn/die
by jeffenstein (Hermit) on May 30, 2018 at 16:45 UTC
|
I'm guessing it's an Americanism. Sorry about that to the rest of the world ;)
"Carping" is slang for complaining about something. ex: He was carping about the wait for a table. "Croaking" is slang for dying. ex: Your pet fish croaked last night
They were rare in my youth, and outside of Perl, I haven't heard them used in probably 30 years.
Update: Just for kicks, here are some synonyms for "carp" from the Merriam-Webster dictionary: bellyache, bleat, caterwaul, croak, fuss, gripe, grouse, nag, whine, and whinge. It could have been worse.
| [reply] |
|
Actually, "carp", used as a verb, meaning complain, has been in use since the 1500s, so is long past the slang stage.
However, "croak" is still considered a slang term.
| [reply] |
|
| [reply] |
|
I agree that PHPisms like 500 extra, semi-overlapping keywords can be a bad thing but I've always liked Carp's interface. Taking the generalized and parameterized route to extremes is warn and die becoming replaced with error($level, $message) or something. I use Carp's functions enough, including longmess and shortmess for logs, that I much prefer having specific functions for acking around and such.
| [reply] [d/l] [select] |
|
|
|
|
I can only guess why Larry & Co. did it this way, and that guess would be that it was to preserve backwards-compatibility with perl 4, which already had the current interface for warn and die.
Did caller exist in perl 4? It kind of makes sense to use a different interface since modules got a lot of changes in 5.0
| [reply] |
|
|
Re^2: Should I use carp/croak or warn/die
by SBECK (Chaplain) on May 30, 2018 at 16:22 UTC
|
Thanks for your reply! When/if you ever release the a module to do this, I definitely would want to use it. I'm learning that I really need to rethink how I do warn/die (or their equivalent).
| [reply] |
Re^2: Should I use carp/croak or warn/die
by Haarg (Priest) on May 31, 2018 at 19:23 UTC
|
Having an option to "carp" from the first caller in a different package would be nice.
This is how carp and croak always work.
| [reply] |
|
Yeah I noticed in the meantime
See Re^4: Should I use carp/croak or warn/die (@CARP_NOT)
Though I'm not happy about the documentation.
the Synopsis says
> warn user (from perspective of _caller_)
But later the doc says inside the text
> carp() or croak() which report the error as being from where your module was called.
| [reply] |
Re^2: Should I use carp/croak or warn/die (@CARP_NOT)
by LanX (Saint) on May 30, 2018 at 20:02 UTC
|
| [reply] |
|
From my experience, mucking with the likes of caller and/or any aspect of such an undertaking of tracking and reporting from nested modules and subs is fraught with frustration, angst, head-desking and oftentimes throwing things... particularly when dealing with anony-subs and the like :)
| [reply] |
|
| [reply] |
|
Though I'm not sure if @CARP_NOT could be used for this ...
How could it?
I mean @CARP_NOT is a package variable that is (or so I suppose) evaluated at compile-time.
How could that be used to implement the run-time feature of reporting the the first caller of a different package?
I don't really know to be honest, you could be right, but my working hypothesis here is that you're simply blah-blahing here.
So please enlighten us...
| [reply] |
|
I wouldn't ask if I knew.
> evaluated at compile-time.
nope that's obvious from the docs and from a simple test.
> you're simply blah-blahing here.
Look who's talking...
Anyway carp() seems to already do by default what I wanted. \o/
It doesn't report from the caller function but the caller package.
use strict;
use warnings;
use Data::Dump qw/pp dd/;
TEST::first(); # <- line 6
#push @main::CARP_NOT, qw(TEST); # uncomment to see dynamic behaviour
#TEST::first();
package TEST;
use Carp;
sub first {
second();
}
sub second {
carp "some warning";
}
some warning at d:/Users/RolfLangsdorf/pm/carp_not.pl line 6.
| [reply] [d/l] [select] |