in reply to Re: Re: Re: Re: Re: Re: Risks in the oblivious use of qr//
in thread Risks in the oblivious use of qr//

I think you are missing the idea behind this,
$regex = qr/test/;
this compiles to (?-xism:test) meaning you are stating that the string test must exist and be lowercase. so ...
if (/$regex OtherWord/i) {...}
This seems very logical to me that this should match "test OTHERWORD" but not "TeSt OtherWord" as I have defined $regex to be case sensitive explicitly ! Are you really stating that you feel you need to
if (/(?-ixsm:$regex) OtherWord/i) { ... }
to accomplish this case insensitivty on the qr var?? That just blows me away.

-Waswas

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: Re: Risks in the oblivious use of qr//
by diotalevi (Canon) on Aug 11, 2003 at 17:12 UTC

    That is exactly what I'm saying. The fact that a qr// regex stringifies with a (?-xism:$re) wrapper doesn't mean to me that it is actually core to it. The regex itself is hard coded into some nodes which actually indicate which of 'ism' apply and its that that you're saying should remain static and I'm saying should bend. Now please keep in mind that I've moderated my stance a bit and I only think /i is acceptable to have this behaviour for. The other three flags 'x', 's' and 'm' have more significant meaning and I can't bring myself to think of a situation where it would make sense to override any of those.

    So really, what I'm saying is that if you had previously said $test = qr/test/ and later said /$test FOO!/i that the /i-ness of the $test object would be overridden and that if you wanted to keep that you'd have to said /(?i:$test) FOO!/i. I had originally written $test = "test" then all of this would behave exactly as I'm suggesting. (except that 'xms' wouldn't be specified either).

      I see what you are saying. But I disagree, with  $test = "test; you are not explicitly stating any regex options whereas  $test = /test/; you are (explicitly stating case sensitive by leaving out the /i). I say take the most detail which would make $test's regex flags higher precedence -- they are more detailed. Lose that efect and you lose a level of detail on the regex. What gain can you see in disregarding how you define a regex's flags earlier in a program? I can see plenty where you would want the regex to act as _YOU_ defined it in the most detail. I guess we are just going to butt heads on this one =)

      -Waswas

        The core difference is that I don't see /test/ as having an explicit absense so much as I see a 'default' going on. Its just not explicit. With /test/i I see an explicit marking on what behaviour to use. I just don't think "explicitly not there" is a good way to think about it. If I meant to be explicitly off then I'd have written (?-i:...).

        Of course I don't actually write that way, that's just how it *should* work.