in reply to Re^3: Converting a stringified regexp back into a regexp
in thread Converting a stringified regexp back into a regexp
I wouldn't! The regexp is used to match XML tag name in handler.
For example this would replace headers by p tags in an XHTML file:
XML::Twig->new( twig_handlers => { qr/^h\d?$/ => sub { $_->set_tag( +'p') }) ->parsefile( "foo.xhtml");
The regexp is stringified then re-build, so in fact the /o is in effect, whether the user wants it or not. And the /g makes no sense, the regexp is not used in a loop, and either it matches and the handler is called, or it doesn't. In any case if there are several handlers of this type, as the stringified version is still used as a key to the hash, there is no garantee that they will always be tested in the same order (actually there is a guarantee under recent perls that they will be tested in different orders every time the code is run).
Does this make sense?
|
|---|