pbeckingham has asked for the wisdom of the Perl Monks concerning the following question:
I am searching for multi-line entities in a string, and while I now have working code, I see a quirk in the use of qr// that I did not expect. Here is the example - I have changed the code to look for HTML comments, which illustrates the quirk.
The output is:#! /usr/bin/perl -w use strict; my $html = qq{ blah <!-- comment --> blah <!-- comment --> blah }; print "m: $_\n" for $html =~ /(<!--.*?-->)/sg; my $r = qr/<!--.*?-->/; print "qr: $_\n" for $html =~ /($r)/sg; $r = qr/<!--.*?-->/s; print "qrs: $_\n" for $html =~ /($r)/g;
The quirk is that the s modifier to the regex must be applied to the qr// construct, and may not be applied to the matching later. The g modifier, and the capturing parens may be added, but not the s.m: <!-- comment --> m: <!-- comment --> qr: <!-- comment --> qrs: <!-- comment --> qrs: <!-- comment -->
Do I have this right? Is there sense, order and logic behind not being able to override these qr// modifiers later?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unexpected qr// behavior
by Paladin (Vicar) on Apr 20, 2004 at 14:53 UTC | |
by bart (Canon) on Apr 20, 2004 at 16:01 UTC | |
|
Re: Unexpected qr// behavior
by diotalevi (Canon) on Apr 20, 2004 at 15:41 UTC | |
by ysth (Canon) on Apr 20, 2004 at 16:13 UTC | |
by diotalevi (Canon) on Apr 20, 2004 at 17:13 UTC | |
|
Re: Unexpected qr// behavior
by rnahi (Curate) on Apr 20, 2004 at 16:14 UTC | |
|
Re: Unexpected qr// behavior
by matija (Priest) on Apr 20, 2004 at 14:55 UTC |