in reply to Weird mod_perl Regex '0' behavior.

This is just a guess, but since the docs for Readonly make no mention of working with Regexp references like what qr// returns your problem might be some interaction between that module and mod_perl. Have you tried it without the Readonly?

If it is something to do with Readonly, you might be able to use the Readonly::Scalar1 procedure to mark just the reference itself as read-only. I'm not sure how the contents of a literal regex would change at a deeper level anyway, so Readonly trying to traverse and mark the referenced values shouldn't be necessary.

Replies are listed 'Best First'.
Re^2: Weird mod_perl Regex '0' behavior.
by vansance (Initiate) on Sep 25, 2008 at 15:19 UTC
    I have tried all the suggestions with no luck.

    I have gone so far as to hard code this in, just to help figure out what is going on...
    my $zero = "0"; if ( $zero eq "0" ) { do_something(); } else { do_something_else(); }
    And it failed!

    I have two potential explanations.
    1. Somehow it is automatically evaluating any "0" string to false, which makes no sense to me.
    2. It is treating the input of "0" as an int, and not as a string, which also makes no sense to me.

    It couldn't even be some bug with the compiler, because I compile the same code as command line only and have no problems.

    Stumped and frustrated.
      Slow down. What you're saying here doesn't make any sense, so I think you must be missing something larger. Remeber, mod_perl doesn't change anything about perl except the life cycle of your program, so this code has to match the first if condition. Something else (configuration? other code before this? the do_something function?) is preventing you from seeing it. Or maybe this is not the real code you're running, in which case we can't help you if you don't show us the real code.
        Perrin, you are right. I got clogged down in the if that I was showing you that I didn't consider the calling method.

        There was nothing wrong with the code that I put in before, the problem was that the method containing that code, is_input_valid, was called within a conditional that didn't check if it was defined, and eval'd '0' as false. ie.
        unless ( is_input_valid() ) { report_bad_input(); }
        And the proper code should have been,
        unless ( defined is_input_valid() ) { report_bad_input(); }
        Very careless of me. I apologize. Thank you for the help.