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

My thinking is that affirmatively setting a flag should override. Since there is no way to positively unset a flag I would expect this to be a case insensitive match. Similarly, if you swapped /i between the expressions I would still expect this to be case insensitive.

Added: I'm going to moderate my opinion here. I thought a bit further and on consideration, the flags /s, /m and /x are likely not safe to have a locally specified flag override. The only qr// flag that could sanely be overridden is /i and in this case I still call the current behaviour a bug.

  • Comment on Re: Re: Re: Re: Risks in the oblivious use of qr//

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Risks in the oblivious use of qr//
by demerphq (Chancellor) on Aug 11, 2003 at 16:14 UTC

    The only qr// flag that could sanely be overridden is /i and in this case I still call the current behaviour a bug.

    Nope. I disagree. If thats a bug then there would be no way to disable /i from inside the regex when the i modifier is used. Which would totally break quite a few regexes that I have. And conversly, would putting a regex compiled with /i into a regex without /i cause the i to cease functioning? Definately not a bug.


    ---
    demerphq

    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

      I'm taking a positivist approach to this. Where /i is specified it overrides, where it is not, it doesn't. So /$re/i has a local definition of /i but /$re/ doesn't. This implies that where a local redefinition occurs you've gained nothing in performance because the regex fragment must be recompiled to match the local expectations. I think that's just too bad. The alternative viewpoints here might be that the potential performance hit is unacceptable (even given the logical disconnect) or that a a regex fragment is actually a universe unto itself and just because it is included in a larger regex the larger regex's rules shouldn't apply.

      I'm still holding out for a positivist interpretation of this.

        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
Re: Re: Re: Re: Re: Risks in the oblivious use of qr//
by waswas-fng (Curate) on Aug 11, 2003 at 13:00 UTC
    I guess my expectations would be precompiled regex are static and immutable in both shape and flag options so the behavior makes sense to me. how would you reap any speed benefit if the interpreter had to reevaluate all locations where qr//'ed regex were used to recompile and apply flags?

    -Waswas

      You wouldn't.