eval 使用 perl 归档解码文件
eval filed decoded files with perl
这里我正在读取目录中的文件列表但是我注意到有些文件无法解码它会在这一行引发错误$tap3->decode($tap_file) or die $tap3->error;
每次我读取新文件时,如果文件有效解码,那么我将对其进行更改列表,然后再次对文件进行编码,否则如果文件损坏无法解码,我将执行另一项任务,但脚本拒绝
printDir(".");
sub printDir{
opendir(DIR, $_[0]);
my @files;
my @dirs;
(@files) = readdir(DIR);
foreach my $file (@files) {
if (-f $file and substr($file,0,2) eq "CD")
{
my $tap3 = TAP3::Tap3edit->new;
my $tap_file = $file;
$result = $tap3->decode("tap_file"); ## decode key
if ( defined $result ) ## here if the file can be decoded then i do changes on it - then encode the file
{
..
..
tap3->encode($tap_file) or die $tap3->error;
}else { ## here if the file courrpted "connot be decoded" then i do another job ...
...
...
$tap3->file_type("TAP");
$tap3->version(3);
$tap3->release(11);
$tap3->structure($notific_struct);
$tap3->encode($file) || die $tap3->error();
}
}
}
closedir(DIR);
}
但它在 ( defined $result )
似乎不起作用
考虑使用点击错误报告来警告错误。
if ( defined $result ) ## here if the file can not be decoded ...
{
..
..
tap3->encode($tap_file) or die $tap3->error;
}else { ## here if the file courrpted "connot be decoded" ...
/// ADD THIS LINE
warn "File: '$file_name' $tap3->error" ;
/// CURRENT CODE FOLLOW
$tap3->file_type("TAP");
$tap3->version(3);
...
.
}
这里我正在读取目录中的文件列表但是我注意到有些文件无法解码它会在这一行引发错误$tap3->decode($tap_file) or die $tap3->error;
每次我读取新文件时,如果文件有效解码,那么我将对其进行更改列表,然后再次对文件进行编码,否则如果文件损坏无法解码,我将执行另一项任务,但脚本拒绝
printDir(".");
sub printDir{
opendir(DIR, $_[0]);
my @files;
my @dirs;
(@files) = readdir(DIR);
foreach my $file (@files) {
if (-f $file and substr($file,0,2) eq "CD")
{
my $tap3 = TAP3::Tap3edit->new;
my $tap_file = $file;
$result = $tap3->decode("tap_file"); ## decode key
if ( defined $result ) ## here if the file can be decoded then i do changes on it - then encode the file
{
..
..
tap3->encode($tap_file) or die $tap3->error;
}else { ## here if the file courrpted "connot be decoded" then i do another job ...
...
...
$tap3->file_type("TAP");
$tap3->version(3);
$tap3->release(11);
$tap3->structure($notific_struct);
$tap3->encode($file) || die $tap3->error();
}
}
}
closedir(DIR);
}
但它在 ( defined $result )
考虑使用点击错误报告来警告错误。
if ( defined $result ) ## here if the file can not be decoded ...
{
..
..
tap3->encode($tap_file) or die $tap3->error;
}else { ## here if the file courrpted "connot be decoded" ...
/// ADD THIS LINE
warn "File: '$file_name' $tap3->error" ;
/// CURRENT CODE FOLLOW
$tap3->file_type("TAP");
$tap3->version(3);
...
.
}