我正在尝试创建使用模块File::Fetch下载的文件的哈希。我正在尝试将下载的文件名及其哈希作为记录存储在数据库中。但是,File::Fetch 对象的任何方法都没有提供下载的文件。有没有办法将文件下载到变量中以创建它的哈希?
这是我的代码片段,
eval{
$uri_handle = File::Fetch->new(uri => $nurl) or die "Could'nt create fetch object\n";
$getfile = $uri_handle ->output_file or die "There is no file to be fetched\n";
my $dir_handle = $uri_handle->fetch( to => $dir2 ) or die "Couldn't fetch file: $uri_handle->error\n";
# print "$getfile was successfully saved to $dir\n";
};
if ($@){
print "\n There is no file at $url\n\n";
}else{
my $file_data_handle = DBI->connect($database_connection_string,$database_user,$database_pass) or die "Couldn't open database: $DBI::errstr\n";
my $file_statement_handle = $file_data_handle->prepare('insert into files (filename,filehash,sourceurl,originalurl) VALUES ($getfile,$filehash,$nurl,$url)') or die "Couldn't prepare statement: $DBI::errstr\n";
$file_statement_handle->execute() or die "Couldn't execute statement: $DBI::errstr\n";
$file_data_handle->disconnect();
}