移动文件的脚本在Perl中不起作用

时间:2017-02-23 15:04:10

标签: linux perl

我有这个脚本来移动文件,但它一直说文件是相同的,因此无法写入

while (my @row = $sth->fetchrow_array) {
    my $id = $row[0];
    my $hash = $row[1];
    my $input_direction = '/home/input/' . $hash;
    my $output_direction = '/var/storage/'.$id;

    opendir(my $dir, $input_direction);

    while(my $file = readdir $dir){
        next if ($file eq "." or $file eq "..");
        my $from = $output_direction . "/" . "$file";
        move($from, $output_direction);
    }
}

以下是错误:

'/var/storage/5/.bashrc' and '/var/storage/5/.bashrc' are identical (not copied) at Move_Files.pl line 38.
Use of uninitialized value $atime in utime at /usr/share/perl5/File/Copy.pm line 393.
Use of uninitialized value $mtime in utime at /usr/share/perl5/File/Copy.pm line 393.

每个文件都会重复几次,没有任何内容可以复制。

有什么想法吗?

2 个答案:

答案 0 :(得分:3)

检查代码:

my $from = $output_direction . "/" . "$file";
move($from, $output_direction);

您可能希望在前一行使用$input_direction

答案 1 :(得分:3)

my $from = $output_direction . "/" . "$file";

应该是

my $from = $input_direction. "/" . "$file";

更好的是:

my $from = $input_direction. "/" . $file;