Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: loop exits after printing the file

by Anonymous Monk
on Jul 06, 2014 at 08:26 UTC ( [id://1092448]=note: print w/replies, xml ) Need Help??


in reply to loop exits after printing the file

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

Replies are listed 'Best First'.
Re^2: loop exits after printing the file
by Mr. Muskrat (Canon) on Jul 07, 2014 at 19:01 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

Re^2: loop exits after printing the file
by myfrndjk (Sexton) on Jul 07, 2014 at 12:33 UTC

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1092448]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (8)
As of 2024-04-18 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found