使用Perl将一个文件的内容导入另一个文件

时间:2011-07-19 14:39:18

标签: perl cp

#!/usr/bin/perl

while (true) {
#Obj: open dir, get flat-file which was exported from bteq and send to a fastload script to be loaded into dev
    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 > 1) {  # check for new files written to the directory
>>>>          # take the copied FlatFile above and import into a fastload script  located at C:/q2refresh/q2Fastload.txt
        else {sleep 100;} #if found nothing new in directory, do nothing.
        }
}

open SOURCE, $newfile;  #reading to file
open SINK, '>>C:/q2refresh/q2Fastload.txt';   #writing to file
    while (<SOURCE>) {
        print SINK $_;
    }
close SOURCE;
close SINK;

请参阅我上面的部分:“&gt;&gt;&gt;&gt;” 。我正在尝试执行复制平面文件内容并将其内容导入快速加载脚本的任务。

Perl是否可以,如果可以,怎么做?

1 个答案:

答案 0 :(得分:1)

你不只是做$result=`cat fileA.txt >> fileB.txt;`