From: Nick C. <ni...@cl...> - 2002-04-11 23:00:59
|
On Thu, Apr 11, 2002 at 03:39:21PM -0700, Nick Cleaton wrote: > > Modified Files: > guestbook.pl > Log Message: > * preserve </body> and </html> in guestlog.html and add them if missing To do that, I've made it rewrite the file in the same way as the guestbook itself. Rather than duplicate all the code for that, I've put the file rewrite code in a sub that takes the name of the file to rewrite and a coderef with which to munge each line. In both cases where I've used this sub, the coderef has turned out to be a closure. This may be too complicated. OTOH the calls to rewrite_file look (and act wrt lexicals) like some sort of user defined control structure, i.e.: my $thing; rewrite_file($filename, sub { # code to munge $_. $thing is used, so this sub # is a closure. }); is a bit like: my $thing; while(<FILE>) { # code to munge $_. $thing is used, but nobody # gets scared. } ... so maybe it's intuitive enough. What do we think ? -- Nick |