這是Perl代碼...將perl代碼轉換爲php? (2)
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");
}
嗯,你需要找到可比的PHP庫來替換Perl代碼使用的庫。這行'HTTP :: Status :: RC_NOT_MODIFIED'對PHP沒有意義。 – quickshiftin 2012-02-20 17:27:35
@quickshiftin這是'304未修改'。有了庫,你可以解析它。看到我的答案。 – 2012-02-20 17:47:43
謝謝你..我仍然在尋找替換 – ansherina 2012-02-20 17:51:00