I'm running on Ubuntu 6.10. Below are my complete (except for Parse.pm which is over 300 lines long...

Main file -
#! /usr/bin/perl use Parse; use Moving; use File::Copy my @filelist = (); # all filenames will go into this global array my $txt_folder = '/temp/'; &check_folders($txt_folder); foreach $file (@filelist) { print "file is $file\n"; Parse::parse_file($file); Moving::move_file($file); } sub check_folders { #iterate thru directory, this works my($dir) = @_; local (*FOLDER); # use local for filehandles my(@subfiles, $file, $specfile); opendir(FOLDER, $dir) or die "cannot open $dir"; @subfiles = readdir(FOLDER); closedir(FOLDER); foreach $file (@subfiles) { # ignore files beginning with a period next if ($file =~ m/^\./); #$specfile = $dir . ':' . $file; $specfile = $dir . $file; if (-d $specfile) { print "directory is $specfile\n"; &check_folders($specfile); # RECURSION } elsif (-f $specfile) { push(@filelist, $specfile); # # do your text line stuff here }#if }#for }#sub __END__

Moving.pm
package Moving; use File::Copy; sub move_file { $oldfile = $_[0]; $newlocation="/data/bst/processed/"; move($oldfile, $newlocation) or die ("Couldn't move file"); return $oldfile } return 1;

Now relevant parts of Parse.pm
package Parse; use File::Copy; use Cwd; use Switch; sub parse_file { use DBI; use DBD::mysql; $dsn = "DBI:mysql:test:localhost"; $dbh = DBI->connect($dsn,"root","",{RaiseError=>1}); $newlocation = "/data/processed/"; $file = $_[0]; print "file is $file\n"; open(INFILE, $file) or die ("Unable to open $file"); while ($line = <INFILE> ) { # parse the file, put stuff in db } #end while print "done parsing\n"; $dbh->disconnect(); close(INFILE); } # end function return 1;

In reply to Re^2: return from external subroutine by kathys39
in thread return from external subroutine by kathys39

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.