... a bug with the module.

The behavior you're seeing is due to confusion between the  // used to delimit the regex and a  / used within the regex. IIRC, Regexp::Common mungs the regex operators | uses the tie-ed hash %RE to support things like  -delim and  -keep and so forth, and apparently the delimiter confusion is passed over silently as a result. "Properly" delimited regexes don't have this problem:

c:\@Work\Perl\monks>perl -wMstrict -le "use Regexp::Common qw[ delimited ]; my $P1 = '../matrix-ops/matopmul.mk'; my $P2 = 'C:\matrix-ops\matopmul.mk'; print \"P1 has path\n\" if ($P1 =~ /$RE{delimited}{-delim => '\/'}/ ) +; print \"P2 has path\n\" if ($P2 =~ /$RE{delimited}{-delim => '\/'}/ ) +; " P1 has path c:\@Work\Perl\monks>perl -wMstrict -le "use Regexp::Common qw[ delimited ]; my $P1 = '../matrix-ops/matopmul.mk'; my $P2 = 'C:\matrix-ops\matopmul.mk'; print \"P1 has path\n\" if ($P1 =~ m{$RE{delimited}{-delim => '\/'}} +); print \"P2 has path\n\" if ($P2 =~ m{$RE{delimited}{-delim => '\/'}} +); " P1 has path P2 has path
What I have for $Regexp::Common::VERSION and $Regexp::Common::delimited::VERSION are 2011121001 and 2010010201, respectively, so what I have installed is a bit old. Same results under both ActiveState 5.8.9 and Strawberry 5.14.4.1.

I don't know if this behavior constitutes a bug in the module or not, but in regexes in general, if a character that's used to delimit the regex appears unescaped within the regex, that's a problem:

c:\@Work\Perl\monks>perl -wMstrict -le "print 'match' if '/' =~ ///; " syntax error at -e line 1, near "/;" Execution of -e aborted due to compilation errors. c:\@Work\Perl\monks>perl -wMstrict -le "print 'match' if '/' =~ /\//; " match

(And BTW: I'm not sure how the presence of a delimited sequence or subsequence signifies a "path"; there may be some semantic confusion here.)

Update 1: If you're interested in more readable regexes, do yourself a huge favor and investigate the  /x regex modifier.

Update 2: Fixed small, cosmetic-only formatting glitch in first two code examples.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Delimiters in Regexp::Common by AnomalousMonk
in thread Delimiters in Regexp::Common by rongrw

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.