Use these and your problem will be easy to solve
Your new program
#!/usr/bin/perl --
use strict;
use warnings;
## uncomment if module already installed in standard places in @INC
#~ use MyFrndJk;
Main( @ARGV );
exit( 0 );
sub Main {
my $dtop = "C:/Users/jeyakuma/Desktop";
my $conf = "$dtop/perl/xpathconfiguration.pl";
my $input = "$dtop/shipping project/input/input.txt";
my $courl = "$dtop/shipping project/url processing/competitors_in_
+url.txt";
my $codir =
"$dtop/shipping project/url processing/competitors_in_directory.
+txt";
my $dbdir = "$dtop/shipping project/database";
## use modules at runtime .. by name .. if installed in $drop/perl
use lib;
lib->import( "$drop/perl" );
require MyFrndJk;
MyFrndJk::create( $conf, $input, $courl, $codir, $dbdir );
MyFrndJk::difference( $conf, $courl, $codir, );
} ## end sub Main
Your new module (fill in the blanks)
package MyFrndJk;
## save as MyFrndJk.pm (so its a module)
use strict;
use warnings;
use autodie; ## error checking for open/close...
our $VERSION = 0.01;
sub create {
my( $xpathConfig, $input, $urlCompetitors, $dirCompetitors, $dirTo
+List ) =
@_;
use autodie qw/ open close opendir closedir /; ## specific
my $config = getConfig( $xpathConfig );
open my( $infh ), '<', $input; ## or die by aut
+odie
open $firstHtmlOut, '>', $urlCompetitors;
while( my $url = <$infh> ) {
$url =~ s/\s+$//; ## CHOMP
my $competitor = domain_check( $config, $url );
print $firstHtmlOut "$competitor.html\n";
}
close $infh;
close $firstHtmlOut;
open my( $compfh ), '>', $competitorsHtml;
opendir my( $dir ), '<', $dirToList;
my @files = grep /\.html$/, readdir $dir;
closedir $dir;
for my $file ( @files ) {
print $comfh "$file\n";
}
close $compfh;
} ## end sub create
## fully quaified name of this subroutine in module MyFrndJk
sub MyFrndJk::CompareMyLists {
...;
} ## end sub MyFrndJk::CompareMyLists
sub MyFrndJk::difference {
my( %args ) = @_;
## code what used to be 'C:/Users/jeyakuma/Desktop/perl/tescm.pl';
} ## end sub MyFrndJk::difference
sub MyFrndJk::getConfig {
my( $confFile ) = @_;
my $s = Safe->new;
$s->permit_only(
"anonlist",
"anonhash",
"pushmark",
"const",
"undef",
"list",
"lineseq",
"padany",
"leaveeval", # needed for Safe to operate, is safe without
+entereval
);
return $s->reval( $confFile );
} ## end sub MyFrndJk::getConfig
1; ## all modules end with this 1
The subroutines take arguments, and they return values, they all use lexical vars (why lexicals ? read Lexical scoping like a fox, Read this if you want to cut your development time in half! )
All code formatted with perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END if " -otr -opr -ce -nibc -i=4 -pt=0 "-nsak=*"