On 7/4/05, Yitzchak Scott-Thoennes <[EMAIL PROTECTED]> wrote: > On Sun, Jul 03, 2005 at 01:53:45PM +0200, demerphq wrote: > > Actually about the only thing that seems to be really "hard" is doing > > comparison of blessed regexes with overloaded stringification. For > > that you need XS if you want it to work always. > > Now there's a sick idea. > > If blessed regexes with overloaded stringification actually work (that > is, the actual regex is accessible to some part of the perl code), > perhaps you could "fix" perl to use the stringification instead? > Then you wouldn't have to worry about it :)
Support for this has been in DDS since a relatively early version. And yes indeed it does work. :-) #!perl -l use overload '""'=>sub {"pie!"}; my $o=bless qr/(foo \w+)/; print $1 if 'bar foo baz bop'=~$o; print $o; __END__ foo baz pie! And i dont think the core should be changed. (Yes i know you were joking, but still. :-) In 5.6.x blessed regexes dont stringify as their pattern even if overload isn't used, so you have to use the regex() function which does the same thing as the core does to find out the pattern. DDS::regex also has the advantage that you can use it to round trip a pattern more easily as in list context you get the pattern and modifier independently. (Without using string manipulation to do it either.) use Data::Dump::Streamer qw(regex); my $r=qr/foo bar baz/is; my ($pattern,$modifiers)=regex($r); if (defined $pattern) { print "qr/$pattern/$modifiers"; } else { print "not a regex"; } __END__ qr/foo bar baz/si -- perl -Mre=debug -e "/just|another|perl|hacker/"