LanX has asked for the wisdom of the Perl Monks concerning the following question:

Hi

Motivation

setting up emacs I noticed that I can provide a regex to classify error-messages into "real error", "warning" or "info". But in perl's messages are no hints about the severity, so by default all messages are classified by emacs alike. And I don't wanna make emacs compare one-by-one with every known error-string.

Question

Whats the best way to enrich these error messages with additional infos? E.g adding the "(W)" or an "(F)" like listed in perldiag?

Use diagnostics would be too verbose ... starting a process running splain a little to much overhead I'd like to avoid.

I started experimenting with CGI::Carp but I'm not sure if this is the best way to do it...

Any idea appreciated!

Cheers Rolf

Replies are listed 'Best First'.
Re: Howto enrich errormessages
by ikegami (Patriarch) on Oct 14, 2009 at 18:06 UTC
    Instead of running
    perl script.pl ...
    run something like
    perl -e' $SIG{__WARN__} = sub { local ( $/, $,, $! ); print STDERR "(W) ", @_, "\n"; }; do shift(@ARGV) or die("(F) $@"); ' script.pl ...
      Thanks Ike!

      $SIG{__WARN__} was the jigsaw piece I was looking for, though your code doesn't work and I'm not sure if you really meant a void if clause.

      Anyway I think the best approach is to extend or subclass diagnostics in a wayto support a "Terse" option. That must be stable.

      Thx! 8)

      Cheers Rolf

Re: How to enrich error-messages?
by bichonfrise74 (Vicar) on Oct 14, 2009 at 19:03 UTC
    Hi ikegami,

    I tried to run what you posted and I seem to be getting a syntax error and I'm not sure how to fix it.
    syntax error at -e line 1, near ");" Execution of -e aborted due to compilation errors.
    Update: I replaced this
    if (!eval { do shift; 1 } or die("(F) $@");
    with this
    if ( !eval { do shift; 1 } ) { die( "(F) $@" ) };
    I'm not sure if this would change the logic of the original code...