#! /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__ #### 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; #### 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 = ) { # parse the file, put stuff in db } #end while print "done parsing\n"; $dbh->disconnect(); close(INFILE); } # end function return 1;