myfrndjk has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks greetings to all.Again I need a help from you .I am trying call a module(create) which will create two text files from there I call another module(difference) to find the difference between those two text files. unfortunately my code exits after printing the text files for the first time.If I run the code second time it will print the results.Every time i have to run the code twice to see the result.Do i have to wait for some time till the file gets created? I tried this but that didn't work.Please help me

sub create { open(FILE, "C:/Users/jeyakuma/Desktop/shipping project/input/input.txt +"); open HTML1,">C:/Users/jeyakuma/Desktop/shipping project/url processin +g/competitors_in_url.txt"; while(<FILE>) { chomp; $url=$_; foreach ($url) { do 'C:/Users/jeyakuma/Desktop/perl/xpathconfiguration.pl'; &domain_check(); $x="$competitor.html"; print HTML1 "$x\n"; } } open HTML2,">C:/Users/jeyakuma/Desktop/shipping project/url processing +/competitors_in_directory.txt"; opendir(DIR, "C:/Users/jeyakuma/Desktop/shipping project/database"); @files = grep(/\.html$/,readdir(DIR)); foreach $file (@files) { print HTML2"$file\n"; } } do 'C:/Users/jeyakuma/Desktop/perl/tescm.pl'; &difference();
use strict; use warnings; use List::Compare; $| = 1; # Disable output buffering for (1..10) { print '.'; sleep 1; } open F, "<C:/Users/jeyakuma/Desktop/shipping project/url processing/co +mpetitors_in_url.txt" or die $!; open S, "<C:/Users/jeyakuma/Desktop/shipping project/url processing/co +mpetitors_in_directory.txt" or die $!; my @a=<F>; my @b=<S>; my $lc = List::Compare->new(\@a,\@b); my @intersection = $lc->get_intersection; my @firstonly = $lc->get_unique; my @secondonly = $lc->get_complement; #print "Common Items:\n"."@intersection"."\n"; print "Please configure and create dump in Databse !!\n"."\n@firstonly +"."\n"; print "please give the input URL for the following !!\n"."\n@secondonl +y"."\n"; close F; close S;

Both modules are individually working fine

Replies are listed 'Best First'.
Re: loop exits after printing the file
by Perlbotics (Archbishop) on Jul 05, 2014 at 17:23 UTC

    What happens if you add ...." or die $!;" to the corresponding open(...) in sub create?

    It's also a good idea to close the files (flush data) when writing is done and before re-opening the files for reading. Add

    close HTML1; close HTML2; close FILE;
    at end of sub create.

Re: loop exits after printing the file
by Anonymous Monk on Jul 06, 2014 at 08:26 UTC

      Sorry Anonymous Monk but that doesn't compile. Substitute $dtop everywhere you find $drop. I haven't tested it any further though.

      ## use modules at runtime .. by name .. if installed in $dtop/perl use lib; lib->import( "$dtop/perl" );

        Mr. Muskrat: Sorry Anonymous Monk but that doesn't compile.

        Fixing typos is normal part of programming that everybody needs to experience and fix, esp noobs :)

        It looks like myfrndjk has had a chance to experience this, thanks for posting a few hours later

      Thanks for your reply will try the same and let you know the result.