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.


In reply to Dumping regexp for Perl versions earlier than 5.14 by perlancar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.