perldelta suggests using this, but it didn't come into being until
5.9.5, so cpan modules may not be able to use it.
automatically incorporate the new modifiers.
Code that needs to work properly with both old- and new-style regexes
automatically incorporate the new modifiers.
Code that needs to work properly with both old- and new-style regexes
-can avoid the whole issue by using:
+can avoid the whole issue by using (for Perls since 5.9.5):
use re qw(regexp_pattern);
my ($pat, $mods) = regexp_pattern($re_ref);
use re qw(regexp_pattern);
my ($pat, $mods) = regexp_pattern($re_ref);
modifiers used when the regular expression was compiled, and C<$pattern>
the actual pattern.
modifiers used when the regular expression was compiled, and C<$pattern>
the actual pattern.
-If the actual stringification is important, you can use something like
-the following:
+If the actual stringification is important, or older Perls need to be
+supported, you can use something like the following:
# Accept both old and new-style stringification
my $modifiers = (qr/foobar/ =~ /\Q(?^/) ? '^' : '-xism';
# Accept both old and new-style stringification
my $modifiers = (qr/foobar/ =~ /\Q(?^/) ? '^' : '-xism';