in reply to Re: Undefined regexp objects?
in thread Undefined regexp objects?

qr// does indeed return a reference, try
print ref(qr//)
This object stringifies through, so you can interpolate it into other patterns.

ihb

Replies are listed 'Best First'.
Re^2: Undefined regexp objects?
by diotalevi (Canon) on Jan 16, 2003 at 00:34 UTC

    In fact... you can also call methods off of it and rebless the object into a different package and it keeps it's Regexp nature.

    use strict; use warnings; my $r = qr/test/; print $r -> match( 'test' ) ? "Match\n" : "No match\n"; bless $r, 'beans'; print $r -> match( 'test' ) ? "Match\n" : "No match\n"; package beans; sub match { $_[1] =~ $_[0] } package Regexp; sub match { $_[1] =~ $_[0] }
      ... rebless the object into a different package and it keeps it's Regexp nature

      Not really. The Regexp nature will disappear, you bless away that. What won't disappear is the fact that the blessed thingy is a MG, i.e. magical. But the Regexp nature will disappear. For instance, you can no longer interpolate the pattern since the string overloading was done by Regexp. So /$re /x won't work the intended way. Note that for /$re/ no interpolation is done, so that still works as expected.

      ihb
        reblessed qr// will work as of 5.8.1.

      FYI, Damian Conway has a section on blessing regular expression references in his Object Oriented Perl book.