On Thu, Jul 24, 2003 at 09:58:40AM +0100, Clayton, Nik [IT] wrote:
> which solves the problem quite simply for moderately sized scripts.

I love it!

> Hmm.  I wonder if I can scope @warnbuffer so that only the __WARN__ and
> __DIE__ subs see it...

Not quite what you want, but how about:

[...]
| package Warn::Delayed;
| use vars qw($warnbuffer);
|
| $warnbuffer=[];
|
| sub get {
|     return $warnbuffer;
| }
|
| package main;
|
| $SIG{__WARN__}=sub { 
|     $opts{verbose} ? warn $_[0] : push @{Warn::Delayed::get()}, $_[0];
| };
|
| $SIG{__DIE__}=sub {
|      $opts{verbose} = 1;
|      print STDERR @{Warn::Delayed::get()};
|      die "PROBLEM: $_[0]";
| };
[...]

Not quite as neat.

Not sure if a Damian way of solving the problem might work, turning the
signals into closures:

| {
|     my @warnbuffer;
|     $SIG{__WARN__}=sub { 
|         $opts{verbose} ? warn $_[0] : push @warnbuffer, $_[0];
|     };
|
|     $SIG{__DIE__}=sub {
|         $opts{verbose} = 1;
|         print STDERR @warnbuffer;
|         die "PROBLEM: $_[0]";
|     };
| }

If that works, then that solves your problem nicely.

-- 
Lusercop.net - LARTing Lusers everywhere since 2002

Reply via email to