in reply to Re: Get regexp modifiers
in thread Get regexp modifiers

I think ref($check_re) ne 'Regexp' can fail in modern Perls. You want to use

use re qw( is_regexp ); is_regexp($check_re)
Or if you want to support Perl < 5.10,
BEGIN { eval 'use re qw( is_regexp )'; if (!defined(&is_regexp)) { my $re_class = ref qr//; *is_regexp = sub($) { local *__ANON__ = 'is_regexp'; return UNIVERSAL::isa($_[0], $re_class); }; } } is_regexp($check_re)

That said, I don't think you should be checking if it's a compiled regex pattern at all. Just checking if it looks like one (as I did) is much more tolerant.

Replies are listed 'Best First'.
Re^3: Get regexp modifiers
by afoken (Chancellor) on Jan 06, 2010 at 09:34 UTC
    I think ref($check_re) ne 'Regexp' can fail in modern Perls.

    Could you explain that? (Or post a link to the relevant documentation?)

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      ./perl -Ilib -le' my $r = ${ qr/abc/ }; print $r; print ref($r) ?1:0; print re::is_regexp($r) ?1:0; print "abc" =~ $r ?1:0; ' (?-xism:abc) 0 1 1

      "sufficiently modern" appears to mean ≥5.12 in this case

        "sufficiently modern" appears to mean ≥5.12 in this case

        Thanks. So it's a problem with the bleeding edge and not with stable and vintage versions, and I still have a lot of time until that problem may bite me.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)