perlancar has asked for the wisdom of the Perl Monks concerning the following question:
My development Perl is 5.18 (but I use perlbrew so I also have e.g. 5.10, 5.20). In one of my modules (DateTime::Format::Alami to be exact), I'm inserting the value of a regex during build time (to reduce startup overhead). The module is meant to use by 5.10+.
Since the Perl used for building is 5.18, the regexp printed contains the (?^...) sequence. As some of you already know, during Perl 5.14 there is a change in regexp stringification:
% perl -E'BEGIN { say $^V } say qr/a/i' v5.10.1 (?i-xsm:a) % perl -E'BEGIN { say $^V } say qr/a/i' v5.18.1 (?^ui:a)
Now, aside from using Perl 5.10 or 5.12 for building, or using Perl 5.10 or 5.12 just to print the regexp during building, are there other alternatives? I'm thinking perhaps there is a CPAN module that emulates stringifying regexp in the way of older Perls.
(Really, Perl is excellent with regards to backward compatibility, but this particular change is a sore pain.)
UPDATE: Sorry, ignore the above problem. I mistakenly thought that I am printing a Regexp object during build time, but actually I am just printing a string. Let me reiterate the question: is there a way (or is there a CPAN module) to make Perl 5.14+ strngify qr/a/i as:
(?i-xsm:a)
and not:
(?^ui:a)
so if I save the stringified regex into a source code in a file, e.g.:
$re = qr/(?i-xsm:a)/;
older Perls can execute the resulting source code?
UPDATE 2014-12-31: Turns out perl5140delta already gives details about this, including the solution to my problem. So I just need to use re's regexp_pattern to extract the pattern and the modifier separately, and just form the old (pre-5.14) stringification myself. SOLVED.
|
|---|