我只想读取文件中的多行.例如,在sample.txt中
"Hi, how are you?" "Hello I'm fine, thank you!"
现在我的问题是如何在不删除句子中的换行符的情况下阅读第二个语句?
编辑:
似乎我的问题不明确.所以我想我应该编辑一下:在我上面的例子中,我需要得到整体,
"Hello I'm fine, thank you!"
while ($line = <PFILE>)
{
#How can I get the statement to $line?
}
Run Code Online (Sandbox Code Playgroud)
如果要一次读取所有行,请更改行分隔符$/:
{
local $/; # change the line separator to undef
$filecontents = <FILE>;
}
Run Code Online (Sandbox Code Playgroud)
如果你想一次读两行,你一次只能读两行.
$lines1_and_2 = <FILE>;
$lines1_and_2 .= <FILE>;
Run Code Online (Sandbox Code Playgroud)