Ok, here's a quick example of what I'm doing:
my $dom = qr{0[1-9]|[12][0-9]|3[01]}; my $month = qr{0[1-9]|1[012]}; my $fourYear = qr{2003}; my $twoYear = qr{03}; my $MMDDYYYY = qr{$month$dom$fourYear}; my $DDMMYYYY = qr{$dom$month$fourYear}; my $YYYYMMDD = qr{$fourYear$month$dom}; my $DDMMYY = qr{$dom$month$twoYear}; my $MMDDYY = qr{$month$dom$twoYear}; my $MMDD = qr{($month$dom)}; my $DDMM = qr{$dom$month}; my $Date = qr{($MMDDYYYY|$DDMMYYYY|$YYYYMMDD|$DDMMYY|$MMDDYY|$DDMM +|$MMDD)}; opendir(DIR,".") or die "Cannot open directory for reading: $1\n"; my @files = grep { /^[^\.|\.\.]/ } readdir(DIR); for (@files) { unless ( $_ =~ /($Date)/g) { no_match($_); next; } my $match = "${^N}:$`--$&--$'"; print "In file -->$_<--\n"; print "$1\n"; }
My thought was that the pattern would be compared in the order it was compiled in $Date, so if $MMDDYYYY matched $_ in the example the matching should stop and report what was matched.

The problem is that for a given line with matches for both $MMDDYYYY and $DDMM the pattern for $DDMM is reported even though the text that matches $MMDDYYYY is first in the line.

If I change $Date to equal just $MMDDYYYY alone the test works correctly and if I change $Date to just $DDMM it returns the appropriate portion. The patterns in $Date are ordered in preference, but it is not returning in that fashion.

My main interest is in discovering if the order of qr() can be different than what was placed in at the compliation of the pattern. It may also be that I have a regex problem, comments on both are welcome.

TIA, Chad.


In reply to qr() match order with multiple patterns by gnu@perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.