English 中文(简体)
在Perl使用预产reg时的问题
原标题:Issues when using pre-compiled regex in Perl

I am having some issues with matching when i try and implement pre-compiled regex in a Perl script. I have the script working without pre-compiling, and any time I have an express that spans lines, it returns no match when pre-compiling. So for example:

my $regex_partner = qr/<h1 id="PartnerName">(?<partner_name>.*?)</h1>/;
$content =~ $regex_partner;
$partner_name = $+{partner_name};

预产工程罚款,但:

my $regex_web =~ qr/Company Website:.*openWindow[(] (?<website>http://.*?) /s;
$content =~ $regex_web;
$website = $+{website};

只剩下一整件事。 看来使用qr/s的时间过长,不会奏效。

帮助?

问题回答

你们有一个打字。

my $regex_web =~ qr/.../s;

That should be:

my $regex_web = qr/.../s;

前者使用<代码>$regex_web。 后者将模式分配到网库。 如果向您发出警告,就会发出“按模式配对的无初始价值网”警告。

Unless it s a打脚石?





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签