Re: Simple compiled regexp not working



"u" == usenet <usenet@xxxxxxxxxxxxxxx> writes:

u> Kindly consider the following code which illustrates my question:
u> #!/usr/bin/perl
u> use strict; use warnings;

u> my $line = '08/29/2006 to 08/30/2006';
u> my $date_rx = qr{m!\d{2}/\d{2}/\d{4}!};

ok, this will make you smack your head in a big D'Oh!

why do you think the m!! INSIDE the qr{} means anything special? the m//
is an op and pair of delimiters and not a regex itself. so since m and /
are not metachars (the / is not a { or }) then they are compiled to
themselves as plain chars to match. and they don't match.

u> print "regexp matches\n" if $line =~ m!\d{2}/\d{2}/\d{4}!;
u> print "date_rx matches\n" if $line =~ /$date_rx/;

u> __END__

u> The way I read perlop, both print statements should fire, as they
u> should be doing the exact same match. But I only see the first one.
u> grrr. This ought to be really simple.

it is simple. you missed the part about the regex itself vs the op and
delimiters.

i will now let you smack yourself silly. no charge.

:)

uri

--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
.



Relevant Pages

  • Re: OT - A wrist watch spamer...
    ... LOL, exactly the scenario I was thinking except that I have to put my ... guitar down to smack the guy in the head and everbody buys me a round ... time spamming you personally in your inbox. ...
    (rec.music.makers.guitar.acoustic)
  • Re: Jobs to get "Rotten Apple award without apology
    ... then smack yourself in the head for your dumb ... Oh, jeez, you're right. ...
    (comp.sys.mac.advocacy)
  • Re: OT - A wrist watch spamer...
    ... LOL, exactly the scenario I was thinking except that I have to put my ... guitar down to smack the guy in the head and everbody buys me a round ...
    (rec.music.makers.guitar.acoustic)
  • Re: Thrilling End To The Season
    ... For every occasion that I have said "F1 is boring", I smack myself ... sharply on the head. ... I can remember the so-called "glory days" of ... Grand Prix, when, having clinched the World Championship earlier, the ...
    (rec.autos.sport.f1)
  • Re: Programme titles I dont get!
    ... At least, off the top of my head, I can't think of any tv ... programmes where the title makes no obvious ... Regarding 'Smack the Pony' - I remember reading an interview with one of the ...
    (uk.media.tv.misc)