我剛剛開始使用Perl,我只是在入門級別,而且我一直在打開文件句柄時遇到問題。打開文件句柄時出錯
下面是代碼:
#!/usr/bin/perl -w
$proteinfilename = 'peptide';
open(PROTEINFILE, $proteinfilename) or die "Can't write to file '$proteinfilename' [$!]\n";
$protein = <PROTEINFILE>;
close PROTEINFILE;
print $protein;
exit;
每次我試圖運行程序,它給了我一個錯誤
readline() on closed filehandle PROTEINFILE at C:\BIN\protein.pl
或
Can't write to file 'peptide' [No such file or directory]
能否請您幫我弄明白這一點。我將文件肽保存爲.txt
,並將其保存在與protein.pl相同的文件夾中。我還能做些什麼來完成這項工作?
該文件是「肽」還是「肽.txt」?你如何運行腳本?腳本的位置在運行時不需要工作目錄。 – geoffspear 2012-03-05 03:34:02