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=*"


In reply to Re: loop exits after printing the file by Anonymous Monk
in thread loop exits after printing the file 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.