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

McGlinchy, Alistair Alistair.McGlinchy at marks-and-spencer.com
Mon Sep 18 15:53:55 BST 2006


> > I have some code with print statements liberally sprinkled 
> throughout 
> > (180 locations at last count).
...
> But.
> 
> *only* 180?
> 
> That's what emacs, M-x grep, M-`, and macros are for. It's 
> called refactoring. Instead of subverting what was originally 
> intended, DO IT RIGHT this time.

Yay! I just got flamed on London PM. Do I qualify for a t-shirt?  

> Five minutes tops.

May I humbly disagree with your proposed solution. Sure five mins to run
a macro. Job done ... but it's not because the code doesn't work
anymore:
	So you tune your macro to cope with prints with and without file
handles
	So you tune your macro to cope with prints with and without ()'s

	d'Oh you forgot to search for all the printf's too.
	then you find a few a select statements (except for the select
that is being used as a sub-second sleep) and spend a long time working
out how your macro will affect them.
	Eek there's an eval in there which you suspect contains prints.
So you need to run a regex on that code too just in case.
	Eeeeeeek a conditional that relies on the return codes of print.
"my $or = print or print OR $or_derie_derie_me'; 
	They didn't mess with $, etc did they?
	How does the pod, __DATA__ and __END__ sections look now? (Note:
pl2bat does some freaky stuff).
	By now you've proved this macro is a null-op to the current
functionality with a side lemma showing P=NP.

I'm not saying this code has the above in it.  But after a quick scan I
can see a "select", so I decided it was better to work around than
within [*].  This code has been stable as a rock for 5 years or more and
will not be needed in less than 6 months. 

My previous solution to this multiple reporting question was to run the
program multiple times ... "Five minute tops".  I thought it was an
effective solution (albeit inelegant hence my post).  

Cheers,

Alistair

PS [*] I'm still excited about tied file handles though. 

**********************************************************************
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