timestamp in STDERR output

Thomas Busch tbusch at cpan.org
Fri Jun 30 10:32:59 BST 2006


Quoting ben fitzgerald <ben at bfitzgerald.co.uk>:

> On Jun 29, 2006 03:19 PM, David Cantrell <david at cantrell.org.uk> wrote:
>
> > On Thu, Jun 29, 2006 at 04:02:46PM +0200, Thomas Busch wrote:
> >
> > > is it possible to redefine STDERR in such a way that
> > > you get a timestamp at the beginning of each line ?
> >
> > #!/usr/bin/perl
> > use strict;
> > use warnings;
> >
> > use Tie::STDERR \&timestamper;
> >
> > sub timestamper {
> >     local *STDERR;
> >     untie *STDERR;
> >     print time().': '.$_[0];
> > }

Hi Ben,
 
> I'm trying to understand perl a little better here!
>
> could you explain why you use untie here having used the typeglob to
> make the STDERR filehandle local to the block?

I must admit I don't get it either as

use Tie::STDERR \&timestamper;

sub timestamper {
    print time().': '.shift;
}

print STDERR "bla\n";

works fine for me.

Thomas.

> does this have a similar effect to select in this case as you print to
> the default filehandle?
>
> thanks very much,
>
> ben.
> 



More information about the london.pm mailing list