in reply to Clean up httpd.conf virtual host mess with perl
Your code looks fine to me. "Elegance" often gets translated to "succinctness", which can often lead to decreasing legibility. (Verboseness can also be hard to read, but your code doesn't suffer from this.)
That said, if you want to save a couple of keystrokes without getting too obscure, you could try
(Actually, that probably didn't save any keystrokes; just avoided creating a new handle.) Also, if you want to use $start and $finish to build your regexp, I would use qr on them:my $content = do { local $/; local @ARGV = 'vhosts.conf'; <> };
And, in this case, I see nothing wrong with putting all your printing in one line:my $start = qr{<VirtualHost \*:80>}; my $finish = qr{</VirtualHost>};
Lastly, if you want to be excruciatingly correct, you should check the return value of all system calls, and that includes not just open but also close. (But, in this case, maybe you should avoid the ARGV trick above, and check the return value of that open as well).print OUT "<VirtualHost *:80>$vhost</VirtualHost>";
But most of these are just personal preferences; whatever improvement they bring to the code, either in terms of readability or "elegance", is marginal at best.
the lowliest monk
|
|---|