After processing all url it will display additional"invalid url" string in else loop for example:If i proces totally 5 urls 3-valid and 2-invalid i get 7 results with 2-additional "invalid string"

use LWP::Simple; use File::Compare; use HTML::TreeBuilder::XPath; use LWP::UserAgent; use Win32::Console::ANSI; use Term::ANSIColor; sub crawl_content { { open(FILE, "C:/Users/jeyakuma/Desktop/shipping project/input/input.txt +"); { while(<FILE>) { chomp; $url=$_; foreach ($url) { ($domain) = $url =~ m|www.([A-Z a-z 0-9]+.{3}).|x; } do 'C:/Users/jeyakuma/Desktop/perl/mainsub.pl'; &domain_check(); my $ua = LWP::UserAgent->new( agent => "Mozilla/5.0" ); my $req = HTTP::Request->new( GET => "$url" ); my $res = $ua->request($req); if ( $res->is_success ) { print "working on $domain\n"; binmode ":utf8"; my $xp = HTML::TreeBuilder::XPath->new_from_url($url); my @node = $xp->findnodes_as_string("$xpath") or print + "couldn't find the node\n" ; open HTML, '>:encoding(cp1252)',"C:/Users/jeyakuma/Des +ktop/shipping project/data_$date/$competitor.html"; foreach(<@node>) { print HTML @node; close HTML ; } } else { print color("green"), "$domain Invalid url\n", colo +r("reset") and open HTML,">C:/Users/jeyakuma/Desktop/log.txt"; print + HTML " $domain Invalid URL"; } } } } } do 'C:/Users/jeyakuma/Desktop/perl/comparefinal.pl'; compare_result(); }

output

footwedrer.eu Invalid url

working on autozona.it

dantae.eu Invalid url

working on infanziabimbo.it

working on footlocker.eu

Invalid url

Invalid url


In reply to if/else loop prints extra values by myfrndjk

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.