Printing to multiple files ... without changing my code.

McGlinchy, Alistair Alistair.McGlinchy at marks-and-spencer.com
Fri Sep 15 12:48:18 BST 2006


Hi all,

I have some code with print statements liberally sprinkled throughout
(180 locations at last count).  I now need to have this code write to a
production and development box every time it runs. It's likely that the
number of locations could grow so can someone please advise what is the
standard idiom for making my standard "print"s go to multiple files? 

I know I can roll my own "tee" sub, I just want to know if there's a way
of doing this without having to change all the print throughout my code
to my_tee statements. 

I've also seen IO::Tee on CPAN but that will also require changing my
code ... won't it?

my @files    = qw( pie.txt pony.txt buffy.txt);
my @handles  = map {open my $x, ">>$_" or die $!; $x} @files;
#... <magic>...
print "Hello\n";  #Magically written to all @files
close $_ for @handles;


Cheers

Alistair

**********************************************************************
Registered Office:
Marks and Spencer plc
Waterside House
35 North Wharf Road
London
W2 1NW

Registered No. 214436 in England and Wales.

Telephone (020) 7935 4422
Facsimile (020) 7487 2670

<<www.marksandspencer.com>>

Please note that electronic mail may be monitored.

This e-mail is confidential. If you received it by mistake, please let us know and then delete it from your system; you should not copy, disclose, or distribute its contents to anyone nor act in reliance on this e-mail, as this is prohibited and may be unlawful.
2005




More information about the london.pm mailing list