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:

  1. 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.

  2. Prefer lexical filehandles, and use the 3-argument form of open:

    open(my $log, '>', $logfile) or die "Cannot open file '$logfile' for w +riting: $!";
  3. 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.

  4. 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
    Hi Athanasius,

    thanks for your help. I will change my code, comment the lines and will try to update as you suggest. Beeing a perl novice it is sometimes not that easy to lern as fast as I want scripts to work ;)

    Thanks - Robert