In my module (DateTime::Format::Alami), I'm building a big regex from potentially hundreds of smaller bits (which will be retrieved from a method and applied some preprocessing). This regex won't change between runs, so in order to save startup time, I'm precomputing it during dist build time. (I don't know how big the saving will be though, so perhaps this is premature optimization.)

There's another use-case where I put regex literal into the built source code with Dist::Zilla: inserting code-generated argument validation code. I do this in some cases where I want the autogenerated argument validation code to be embedded directly into the source code and not generated/called dynamically during runtime (and thus usually adds another subroutine call level or startup overhead time, because in my case the argument validation code generator has quite a bit of startup time). An example:

sub foo { my ($arg1, $arg2) = @_; # INSERT CODE VALIDATION HERE ... }

During build, a Dist::Zilla plugin will fill in the code validation routine:

sub foo { my ($arg1, $arg2) = @_; defined($arg1) or die "arg1 is required"; $arg1 =~ qr/\A\w+\z/ or +die "arg1 must be alphanums only"; defined($arg2) or die "arg2 is req +uired"; # INSERT CODE VALIDATION HERE ... }

I hope that clears up things a bit.

And even if the above two use-cases are not commonly had with other programmers, I'm still curious about the problem of handling regex stringification backward-incompatibility in Perl 5.14.


In reply to Re^2: Dumping regexp for Perl versions earlier than 5.14 by perlancar
in thread 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.