向 chat.deepseek.com 提问:请将这个 python 脚本翻译为 perl 语言脚本
参阅:Python 调用 DeepSeek API 完整指南
将 Python 脚本翻译为 Perl 语言脚本时,需要注意两种语言之间的语法差异。以下是将给定的 Python 脚本翻译为 Perl 的版本: test_deepseek_v1.pl
use strict;
use warnings;
use utf8;
use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;
use POSIX qw(strftime);
use Encode qw(encode decode);
# 保存对话内容到文件
sub save_to_file {
my ($file, $content, $is_question) = @_;
my $timestamp = strftime("%Y-%m-%d %H:%M:%S", localtime);
if ($is_question) {
print $file "\n[$timestamp] Question:\n$content\n\n[$timestamp] Answer:\n";
} else {
print $file $content;
}
}
# 主函数
sub main {
# 配置
my $url = "https://api.siliconflow.cn/v1/chat/completions";
my $headers = {
"Content-Type" => "application/json",
"Authorization" =>

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



