“Why, yes,” you reply, “one can say in a regex”:
$ perl -E '/(?{ say "See?" })/'
See?
“But,” I reply, “what if you want to interpolate a pattern?”
$ perl -E 'use re "eval"; my $a = qr//; /(?{ say("See?") })$a/'
Undefined subroutine &main::say called at (re_eval 1) line 1.
Thoughts?
UPDATE: ambrus suggested in the CB to remind the compiler that I want to use 5.010, and that works:
$ perl -E 'use re "eval"; my $a = qr//; /(?{ use 5.010; say "See?" })$
+a/'
See?
which solves my problem, but seems strange. Why should the presence or absence of an empty regex require me to add an apparently superfluous
use?
UPDATE:
ambrus answered that, too. It's because the interpolated regex changes the big regex from a constant that can be compiled at compile time, to something not known to be constant that must be compiled at run time. Ah, well. I was too eager to post. :-)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.