On Sun, Apr 24, 2011 at 11:18 PM, Uri Guttman <u...@stemsystems.com> wrote:
> a small request. you can post link to pastebots but also paste the code > in emails here. i can reply and quote code better staying in my emailer > than going back and forth to a web page. emacs does a fine job of > marking off quoted emails which i don't get when using a pastebot. > > Sure, my bad. I got tired of GMail screwing up my indentation, but hadn't considered that others might not be so impaired. Here's the code for future reference: use 5.010; my $string = 'Some string'; my $string_regex = '([A-Za-z])'; my $as_regex = qr/$string_regex/; my $quoted_regex = qr/\Q$string_regex/; say "Without \\Q, against [$string], [$string_regex] is interpreted as [$as_regex] and ", match_against($string, $as_regex); say "Without \\Q, against [$string_regex], [$string_regex] is interpreted as [$as_regex] and ", match_against($string_regex, $as_regex); say ""; say "With \\Q, against [$string], [$string_regex] is taken literally as [$quoted_regex] and ", match_against($string, $quoted_regex); say "With \\Q, against [$string_regex], [$string_regex] is taken literally as [$quoted_regex] and ", match_against($string_regex, $quoted_regex); $as_regex = qr/(\Q$string_regex\E)/; say "\nBonus: Against [$string_regex], [(\\Q$string_regex\\E)] is interpreted as [$as_regex] and ", match_against($string_regex, $as_regex); sub match_against { my ($string, $regex) = @_; return $string =~ $regex ? "matched, with \$1 => [$1]" : "didn't match."; } <was that polite enough for the tone phreaks out there?> :) Just in case, drop the caps everywhere! :P Brian.