The below code I’m trying to produce is trying to do this:
What I’m trying to do is running a BTEQ script that gets data from a DB then exports to a flat-file, that flat file is picked up my a Perl script (the above code), then with this post trying to get perl to import that file it gets into a fastload file. Does that make more sense?
while (true) {
#Objective: open dir, get flat-file which was exported from bteq
opendir (DIR, "C:/q2refresh/") or die "Cannot open /my/dir: $!\n"; #open directory with the flat-file
my @Dircontent = readdir DIR;
$filetobecopied = "C:/q2refresh/q2_refresh_prod_export.txt"; #flatfile exported from bteq
$newfile = "C:/q2refresh/Q2_FastLoadFromFlatFile.txt"; #new file flat-file contents will be copied to as "fastload"
copy($filetobecopied, $newfile) or die "File cannot be copied.";
close DIR;
my $items_in_dir = @Dircontent;
if ($items_in_dir > 2) { # > 2 because of "." and ".."
-->>>>>> # take the copied FlatFile above and import into a fastload script located at C:/q2refresh/q2Fastload.txt
}
else {sleep 100;}
}
I need help with implementing the above bolded section. How do I import the contents of C:/q2refresh/Q2_FastLoadFromFlatFile.txt into a fastload script located at C:/q2refresh/q2Fastload.txt.
// I apologize if this is somewhat newbish, but I am new to Perl.
Thanks.
Well, when including
.and.., plus the two copies ofq2_refresh_prod_export.txt, you will always have more than 2 files in the directory. If such a case should occur thatq2_refresh_prod_export.txtis not copied, the script willdie. So theelseclause will never be called.Also, it is pointless to copy the file to a new place, if you are simply going to copy it to another place in a second. It’s not like “cut & paste”, you actually, physically copy the file to a new file, not a clipboard.
If by “import into” mean that you want to append the contents of
q2_refresh_prod_export.txtto an existingq2Fastload.txt, there are ways to do that, such as what Troy suggested in another answer, with anopenand>>(append to).You will have to sort out what you mean by this whole
$items_in_dircondition. You are keeping files and copying files in that directory, so what is it exactly that you are checking for? Whether the files have all been removed (by some other process)?