正如本網站上的用戶Chris所建議的。在第一個Perl腳本中:值存儲在字典中。第一個腳本很好。第一個腳本只運行一次並存儲值。這是工作。perl中文件的位置
在第二腳本:
我的$ =處理檢索( 'processed_dirs.dat'); #$ processed is a hashref
這裏是讀取第一個腳本中的「processed_durs.dat」。所以,我只是想知道第二個腳本如何知道Processed_dirs.dat的位置?
#!/usr/bin/perl
use strict;
use warnings;
use Storable;
# This script to be run 1 time only. Sets up 'processed' directories hash.
# After this script is run, ready to run the daily script.
my $dir = '.'; # or what ever directory the date-directories are stored in
opendir my $dh, $dir or die "Opening failed for directory $dir $!";
my @dir = grep {-d && /^\d\d-\d\d-\d\d$/ && $_ le '11-04-21'} readdir $dh;
closedir $dh or die "Unable to close $dir $!";
my %processed = map {$_ => 1} @dir;
store \%processed, 'processed_dirs.dat';
第二腳本:
#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
use Storable;
my $dir = shift or die "Provide path on command line. $!";
my $processed = retrieve('processed_dirs.dat'); # $processed is a hashref
opendir my $dh, $dir or die "Opening failed for directory $dir $!";
my @dir = grep {-d && /^\d\d-\d\d-\d\d$/ && !$processed->{$_} } readdir $dh;
closedir $dh or die "Unable to close $dir $!";
@dir or die "Found no unprocessed date directories";
my $fdir = '/some/example/path';
for my $date (@dir) {
my $dday = "$dir/$date";
my @gzfiles = glob("$dday/*tar.gz");
foreach my $zf (@gzfiles) {
next if $zf =~ /BMP/ || $zf =~ /LG/ || $zf =~ /MAP/ || $zf =~ /STR/;
print "$zf\n";
copy($zf, $fdir) or die "Unable to copy $zf to $fdir. $!";
}
$processed->{ $date } = 1;
}
store $processed, 'processed_dirs.dat';
我不明白這個問題,但我從來沒有硬編碼過文件名或目錄名作爲原則問題,所以如果這是我的腳本,答案會很清楚:信息在命令行上。 – reinierpost