Getstore到Buffer,不使用临时文件

时间:2013-11-14 15:42:06

标签: perl file-handling

我最近开始使用Perl并且混合了很多东西来获得我想要的东西。

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

然后我打开一个文件处理程序,插入文件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);

感谢您的帮助

1 个答案:

答案 0 :(得分: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

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

对于您的第二个问题,请使用open $fh, '<', $filepath之类的开放。您可以使用perldoc -f open查看更多信息。

相关问题