我试图生成的下面的代码试图这样做:
我要做的是运行一个BTEQ脚本,该脚本从DB中获取数据,然后导出到一个平面文件,该平面文件将获得我的Perl脚本(上面的代码),然后在本文中试图让perl导入该文件,然后将其导入一个fastload文件中。这更有意义吗?
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;}
}我需要执行上述粗体部分的帮助。如何将C:/q2refresh/Q2_FastLoadFromFlatFile.txt的内容导入位于C:/q2refresh/q2Fastload.txt的fastload脚本。
//如果这有点新意,我很抱歉,但我对Perl并不熟悉。
谢谢。
发布于 2011-07-15 15:20:44
if ($items_in_dir > 2) { # > 2 because of "." and ".."当包含.和..,再加上两个q2_refresh_prod_export.txt副本时,目录中总是有两个以上的文件。如果出现这样的情况,即q2_refresh_prod_export.txt未被复制,则脚本将die。因此,else子句永远不会被调用。
而且,如果您打算在一秒钟内将文件复制到另一个地方,那么将文件复制到一个新位置是没有意义的。它不像“剪切和粘贴”,你实际上,物理复制文件到一个新的文件,而不是剪贴板。
如果“导入”意味着要将q2_refresh_prod_export.txt的内容附加到现有的q2Fastload.txt中,那么有一些方法可以做到这一点,比如Troy在另一个答案中建议使用open和>> (附加到)。
您必须弄清楚整个$items_in_dir条件是什么意思。您将文件和复制文件保存在该目录中,那么您要检查的到底是什么?文件是否全部被删除(通过其他进程)?
发布于 2011-07-15 14:39:36
我不知道你想做什么。你就想这么做吗?
open SOURCE, $newfile;
open SINK, '>>C:/q2refresh/q2Fastload.txt';
while (<SOURCE>) {
print SINK $_;
}
close SOURCE;
close SINK;这将将$newfile的内容附加到您的fastload文件中。
https://stackoverflow.com/questions/6708407
复制相似问题