in reply to Re: Walks like a regex, quacks like a regex...
in thread Walks like a regex, quacks like a regex...

Hang on, but that only works in the case:
regex1 => qr/foo/
But not in the case:
regex2 => '(?-xism:foo)'
Where regex1 is compiled as a Regexp, and regex2 is compiled as a string. The reference to regex1 yields a Regexp, the reference to regex2 yeilds nothing, so it will not match regex2 which is a valid regular expression.

Replies are listed 'Best First'.
Re: Re: Re: Walks like a regex, quacks like a regex...
by shenme (Priest) on Sep 23, 2003 at 05:48 UTC
    Well that was (is) my confusion at his mentioning the phrase "a real quoted regex".   _If_ he means a compiled qr() regex then while he's still throwing the result reference value around the ref() is the right way to check.

    But once he forces the qr() reference value to be stringified, it'll end up in the "(?-xism:^[Zz]owie!?$)" form and he'll have to recognize that 'unique' format.

    And then his checking will fail because the leading part shows which options are and are not in effect.   Using qr{^Zzowie!?$}sm will, when stringified, result in "(?ms-xi:^[Zz]owie!?$)".   Zowie!

      Sweet -- this is exactly the discussion I wanted to see, and a nice answer. I thought of 'ref' earlier, but my perldoc tells me:
      Builtin types include:
      
        SCALAR
        ARRAY
        HASH
        CODE
        REF
        GLOB
        LVALUE
      
      ...so I didn't think it was possible. Thank you.
      --
      man with no legs, inc.

        In the years since I've written this node, UNIVERSAL::isa has been published. Use that instead.


        In that case you should use isa() and test for 'Regex'. You'll allow for blessed regexen this way. Simple ref() tests don't account for that.

        *isa = \&UNIVERSAL::isa; sub regex_tester { my $thingie = shift; return isa( $thingie, 'Regex' ); }