簡體   English   中英

使用Perl在Windows中輸入和讀取文件時遇到問題

[英]Having problems with file input and reading in Windows with Perl

我試圖讀取與Perl腳本相同的目錄中的文件作為輸入,並使用Perl在Windows中從中讀取。

碼:

$inputFile =  getcwd . "/" . <STDIN>;
open (FILE, chomp($inputFile)) or die "Cannot open $inputFile: $!\n";   
@lines = <FILE>;
print "@lines\n";

我得到的錯誤是:

C:/Documents and Settings/username/workspace/test.pl  No such file or directory

即使該文件確實存在於該確切目錄中的確切形式。 我也嘗試將“文檔和設置”放在引號中。

chomp的返回值不是chomped值。 open之前將chomp排除在外,你應該沒事。

順便說一句, getcwd是不必要的; 當前目錄的概念意味着在沒有完整路徑的情況下查看的位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM