if statement - program is terminated after else condition in perl -
if statement - program is terminated after else condition in perl -
after encountering else condition(invalid url) loop terminated , not processing farther urls. 2. if node fails in xpath not printed in screen or file.i want print in both file , screen (node exception)
use lwp::simple; utilize file::compare; utilize html::treebuilder::xpath; utilize lwp::useragent; utilize win32::console::ansi; utilize term::ansicolor; sub crawl_content{ { open(file, "c:/users/jeyakuma/desktop/input/input.txt"); { while(<file>){ chomp; $url=$_; foreach ($url){ $domain) = $url =~ m|www.([a-z a-z 0-9]+.{3}).|x; } 'c:/users/jeyakuma/desktop/perl/mainsub.pl'; &domain_check(); $ua = lwp::useragent->new( agent => "mozilla/5.0" ); $req = http::request->new( => "$url" ); $res = $ua->request($req); if ( $res->is_success ){ print "working on $domain\n"; binmode ":utf8"; $xp = html::treebuilder::xpath->new_from_url($url); @node = $xp->findnodes_as_string("$xpath") or print "couldn't find node\n" ; open html, '>:encoding(cp1252)',"c:/users/jeyakuma/desktop/ project/data_$date/$site.html"; foreach(<@node>){ print html @node; close html ; } } else{ print color("green"), "$domain invalid url\n", color("reset") , open file,">c:/users/jeyakuma/desktop/log.txt"; print file " $domain invalid url"; } } } } } 'c:/users/jeyakuma/desktop/perl/comparefinal.pl'; compare_result(); }
the else
status reopens file
writing file. thus, @ next iteration of while (<file>)
loop, perl effort read file
, fail (because it's available writing, not reading), , loop end. need utilize name other file
in else
condition.
perl if-statement
Comments
Post a Comment