in reply to Re^2: Find & Delete by comparing two files
in thread Find & Delete by comparing two files
Hello again perlpoda,
Glad your code is working. Here are a few ways to improve it, in addition to the suggestions made by nemesdani:
Always begin your scripts with:
use strict; use warnings;
strict will force you to pay attention to the scope of your variables, which is a good thing.
Prefer lexical filehandles, and use the 3-argument form of open:
open(my $log, '>', $logfile) or die "Cannot open file '$logfile' for w +riting: $!";
As nemesdani noted, it is better to avoid opening and closing files any more than necessary. In this case, you open LOGFILE for writing and then don’t close it. So later, in the foreach loop, there is no need to open it again for appending: it’s still open, just write to it! Leave it open within the loop, then close it explicitly — once — after the loop.
Add comments. For example, what is the code re-writing $newUrl all about? I have no idea, and chances are neither will you — when you come back to this script in, say, 6 months’s time.
nemesdani has given you some good ideas about deleting whole lines. You’re making progress, keep going!
Athanasius <°(((>< contra mundum
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Find & Delete by comparing two files
by perlpoda (Initiate) on Sep 11, 2012 at 13:19 UTC |