Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Perl中仅从网页内容中获取特定行_Perl - Fatal编程技术网

如何在Perl中仅从网页内容中获取特定行

如何在Perl中仅从网页内容中获取特定行,perl,Perl,我使用下面的代码来获取网页内容。它工作得很好,但我想从中得到具体的信息。非常感谢您的帮助 use strict; use warnings; use LWP::Simple; my $content = get('http://www.w3schools.com/'); print $content; my @arr; my $flag = 0; push (@arr, $content); #print @arr; my $find = "HTML 4.01"; for (@arr) {

我使用下面的代码来获取网页内容。它工作得很好,但我想从中得到具体的信息。非常感谢您的帮助

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

my $content = get('http://www.w3schools.com/');
print $content;
my @arr;
my $flag = 0;
push (@arr, $content);
#print @arr;

my $find = "HTML 4.01";
for (@arr)
{
  if ($_ =~ /$find/) 
  {
    print "$_\n";
    print "passed\n";
    $flag = 1;
  }
}

if ($flag == 1)
{
  print "Testcase passed";
}
else
{  
  die "Testcases fails";
}

get
将整个内容作为单个值获取。如果您想按生产线进行处理,首先


get
将整个内容作为单个值获取。如果您想按生产线进行处理,首先


我的$flag=$content=~/$find/i;我的$flag=$content=~/$find/i;非常感谢您的帮助:-)user1583773,在堆栈溢出上,一个人说谢谢并回答。有人能解释一下拆分qr/\R/在技术上做了什么吗?什么是qr?@Memoc:qr//引入了一个正则表达式。请参阅中的Regexp引号Like Operators。非常感谢您的帮助:-)user1583773,在堆栈溢出上,一个人说“谢谢”和“回答”。有人能解释一下拆分qr/\R/在技术上做了什么吗?什么是qr?@Memoc:qr//引入了一个正则表达式。请参见中的Regexp Quote-Like运算符。
use strict;
use warnings;
use LWP::Simple qw(get);

for my $line (split qr/\R/, get('http://www.w3schools.com/')) {
    print $line if $line =~ /\QHTML 4.01/;
}