这是perl代码...
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Date;
my $taxon = $ARGV[0]; # Taxonomy identifier of organism.
my $query = "http://www.uniprot.org/uniprot/?query=organism:$taxon&format=fasta&include=yes";
my $file = $taxon . '.fasta';
my $agent = LWP::UserAgent->new;
my $response = $agent->mirror($query, $file);
if ($response->is_success) {
my $results = $response->header('X-Total-Results');
my $release = $response->header('X-UniProt-Release');
my $date = sprintf("%4d-%02d-%02d", HTTP::Date::parse_date($response->header('Last-Modified')));
print "Downloaded $results entries of UniProt release $release ($date) to file $file\n";
}
elsif ($response->code == HTTP::Status::RC_NOT_MODIFIED) {
print "Data for taxon $taxon is up-to-date.\n";
}
else {
die 'Failed, got ' . $response->status_line .
' for ' . $response->request->uri . "\n";
}
我试过把它转换为php ... 仍然存在错误的代码行:在else if语句中 如果您发现其他错误,请在此处发表评论......
这是我到目前为止所尝试的内容
$taxon = $ARGV[0]; # Taxonomy identifier of organism.
$query = "http://www.uniprot.org/uniprot/?query=organism:$taxon&format=fasta&include=yes";
$file = $taxon . '.fasta';
$response = $agent->mirror($query, $file);
if ($response->is_success) {
$results = $response->header('X-Total-Results');
$release = $response->header('X-UniProt-Release');
$date = sprintf("%4d-%02d-%02d", date_parse($response->header('Last-Modified')));
print "Downloaded $results entries of UniProt release $release ($date) to file $file\n";
}
elsif ($response->code == HTTP::Status::RC_NOT_MODIFIED) {
print "Data for taxon $taxon is up-to-date.\n";
}
else {
die ('Failed, got ' . $response->status_line .
' for ' . $response->request->uri . "\n");
}
答案 0 :(得分:3)
我不相信你可以在php,托盘elsif
中使用else if
。
答案 1 :(得分:1)
elsif失败的原因是因为它需要是elseif。
答案 2 :(得分:1)
你在哪里运行这个脚本? $ARGV
是perl在命令行中使用的。如果您从表单中获取信息,请使用发布或获取方法(使用$_POST
和$_GET
访问)。
将elsif
替换为elseif
。
您可以调用$agent->mirror
之类的内容,但这里没有定义它们。
正如quickshiftin指出的那样,你不能引用Perl库 - 你必须找到PHP等价物。
答案 3 :(得分:1)
答案 4 :(得分:1)
使用此WebGet课程。
require("WebGet.php");
$taxon = $argv[0];
$agent = new WebGet();
$agent->useCache = true;
$agent->cacheLocation = '/tmp';
touch('cookie.txt');
$agent->cookieFile = 'cookie.txt';
$query = "http://www.uniprot.org/uniprot/?query=organism:$taxon&format=fasta&include=yes";
$file = $taxon . '.fasta';
$agent->requestContent($query);
if($agent->responseStatusCode==200){
$results = $agent->responseHeaders[strtoupper('X-Total-Results')];
$release = $agent->responseHeaders[strtoupper('X-UniProt-Release')];
$date = date("Y-m-d", strtotime($agent->responseHeaders[strtoupper('Last-Modified')]));
print "Downloaded $results entries of UniProt release $release ($date) to file $file\n";
} // 304 Not Modified
elseif($agent->responseStatusCode==304){
print "Data for taxon $taxon is up-to-date.\n";
}else{
die ('Failed, got ' . $agent->responseStatusLine .
" for uniprot/?query=organism:$taxon&format=fasta&include=yes\n");
}