Hello, thanks for getting back to my problem. Ok, let's see - I have this pretty ugly code I managed to write and it is working. I'm sure there are nicer ways to achieve my goal but I'm a complete beginner - sorry:
#!/usr/bin/perl use LWP::Simple; $elem1 = "http://www.test.de/subfolder/"; $elem3 = "http://www.test.de/subfolder/de/"; # --------- Logfile ---------------------------- my $delimiter = "\t"; my $logfile = "errorlog.txt"; my $datum = localtime(); my $logmsg = "$datum $ENV{USER} Broken Links"; open LOGFILE, ">$logfile" or die $!; print LOGFILE $logmsg, "\n"; # --------- Open File ----------------------- open(READ,"Linkfile.csv") or die $!; while (my $line = <READ>){ if($line=~/\d+\t/){ my @liste = split($delimiter,$line); push(@urls,$liste[2]); } } close READ; # ---------------------------------------------- foreach (@urls) { chomp($_); if (head($_)) { print $_." is working.\n\n"; } else { print $_." is broken.\n\n"; open LOGFILE, ">>$logfile" or die $!; print LOGFILE "\n".$_." is broken."; close LOGFILE; $tmp_url = "$_."; @array=split(/\?/,$_); $myString = $array[0]; if ($myString =~ m#http:\/\/www.test.de\/subfolder\/de\/#) { $myString =~ s#http:\/\/www.test.de\/subfolder\/de\/##; $newUrl = $elem1.$myString; } else { $myString =~ s#http:\/\/www.test.de\/subfolder\/##; $newUrl = $elem3.$myString; print $newUrl." generated \n\n"; } if (head($newUrl)) { print $newUrl." is working.\n\n"; open LOGFILE, ">>$logfile" or die $!; print LOGFILE "\n".$newUrl." is working.\n"; close LOGFILE; } else { print $newUrl." isn't working, too.\n\n "; open LOGFILE, ">>$logfile" or die $!; print LOGFILE "\n".$newUrl." isn't working, too.\n"; close LOGFILE; } } }

Basicaly it does the following: Open the File, gettinge the 3. tabulated text and testing it if the server responds with a 200 (all ok) or 404 (not found.)

If the Link is broken, it is testing it if there's only a problem with the subfolder and generating a new url. Testing the head of this link.

So I have a file now with all the broken links - what I want to do is to delete these broken links in my original file.

PROBLEM is that I don't want to delete just the link but the whole line in the original file.

I'm sorry if I can't describe it better - English is not my mother tongue ;)

Thanks in advance. Regards, Robert

In reply to Re^2: Find & Delete by comparing two files by perlpoda
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.