2013-11-14 34 views
1

我最近开始Perl,并混合了很多东西来获得我想要的。Getstore缓冲区,不使用临时文件

我的脚本获取网页的内容,将其写入文件。

然后我打开一个文件处理程序,将文件report.html插入(对不起,我不是英文,我不知道怎么说更好)并解析它。 我写的每一行我遇到一个新的文件,除了包含特定颜色的行。

它的工作原理,但我想尝试另一种方式,不需要我创建一个“report.html”临时文件。此外,我想直接在文件中打印我的结果,我不想使用系统重定向'>'。这意味着我的脚本必须由另一个.sh脚本调用,而我不希望这样。

use strict; 
use warnings; 
use LWP::Simple; 

my $report = "report.html"; 

getstore('http://test/report.php', 'report.html') or d\ 
ie 'Unable to get page\n'; 

open my $fh2, "<$report" or die("could not open report file : $!\n"); 

while (<$fh2>) 
{ 
print if (!(/<td style="background-color:#71B53A;"/ .. //)); 
} 

close($fh2); 

感谢您的帮助

回答

0

如果你已经拿到了HTML内容到一个变量,你可以在这个变量使用open通话。像:

my $var = "your html content\ncomes here\nstored into this variable"; 
open my $fh, '<', \$var; 

# .. just do the things you like to $fh 

您可以尝试在LWP::Simple模块get功能;)

要将sencond问题,使用开放像open $fh, '<', $filepath。您可以使用perldoc -f open查看更多信息。

相关问题