Использование Perl для импорта содержимого одного файла в другой

#!/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;

Пожалуйста, смотрите раздел выше, где я написал это: ">>>>" . Я пытаюсь выполнить эту задачу по копированию содержимого плоского файла и импорту его содержимого в скрипт быстрой загрузки.

Возможно ли это в Perl, если да, то как?


person Jshee    schedule 19.07.2011    source источник
comment
Что такое скрипт быстрой загрузки? Можете ли вы опубликовать небольшой пример q2_refresh_prod_export.txt и желаемый формат для q2Fastload.txt?   -  person Will Sheppard    schedule 19.07.2011


Ответы (1)


Не могли бы вы просто сделать $result=`cat fileA.txt >> fileB.txt;`.

person Eamorr    schedule 19.07.2011