Hello wisiest ones! for first time in my 'career' I considering to modify $SIG{__WARN__}.

Until now I have considered this like something of Magic an Power never disclosed to other then Perl fellows.. so I never played with it in a reverencial ignorance (I suspect also that a BAD or Buggy signal handler is dangerous like a mad dog).

Now, when the ChatterBox is empty like my bank-account, I'm write a little module in which I wont to use Carp's cluck and confess facility and I want to log succes and failure so my first approach in the caller script was:
use MyLittlePlace::BrandNewMod qw(a b c); close STDERR; open(STDERR, ">&STDOUT") || die " uh uh ?! we mad ?! "; $|++;
so that I can log to a file all the return output with useful information and in the right order..

Then the 'UcanDObetter' devil told me 'you dont want a dayly spam mail full of OK report, true? invent some kind of trigger that fire an advise on more then zero errors..'.

Mmh.. I have SuperSearched this and I replaced the above code in this way in the caller script:
close STDERR; # no more redirect of handler # open(STDERR, ">&STDOUT") || die " uh uh ?! we mad ?! "; $|++; my $err_count = 0; $SIG{__WARN__} = sub { ++$err_count;print STDOUT @_ }; $SIG{__DIE__} = sub { ++$err_count;print STDOUT @_ }; #do all the stuff and at the end.. &advise_me($content) if $err_count > =; print $err_count, " ERROR",($err_count eq 1 ? '' : 'S' ), " IN $0\n";
Is a Rigth thing to do in my case? is better do it in the module in some way ? it is dangerous? it make sense?

thks in advance

Lor*

In reply to doubious about redefine $SIG{__WARN__} by Discipulus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.