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


In reply to Re^3: Find & Delete by comparing two files by Athanasius
in thread Find & Delete by comparing two files by perlpoda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.