Does anyone else think that adding /e to qr// would
be a good idea? I recently found myself doing something
like this:
my @days = qw( Sun Mon Tue Wed Thu Fri Sat );
my $days_re = qr/join '|', @days/e;
And was quite surprised that it didn't just work. There
are obvious workarounds, but they feel awkward:
my $days_re = do { my $tmp = join '|', @days; qr/$tmp/ };
(Yes, in this particular case, I could abuse
$"... but that still takes a
do BLOCK and a
local.)
Update
-
Yes, I know that this is not how the language
works right now. What I was trying to ask is
whether others thought this might be an
interesting or useful or non-damaging feature.
-
Note that I am only suggesting /e apply to the
regex guts in qr//. Not in m//, not in s///.
-
I tried to demonstrate in my example that I
would like the /e to apply exactly once, at
the time the qr// is evaluated. I understand
that this is not how the other qr// modes
work (as they are applied at time of use).
This is exactly the sort of wart that I was
hoping people would point out, and it is
appreciated.
-
I also discussed this on at least one PM list,
so I might be confused about what I clarified there
vs. what I clarified here. :) Apologies!
So far, people (including myself! :) have demonstrated
that this is not a necessary feature. The
opinion seems mostly against whether this
would be a desirable feature.
It is just a pattern that I've found myself using
quite often lately. My preference for a one-line
approach is that I like the most important things
to be closer to the left side: what I really want
to know is that I'm compiling a regex object. Whether
I'm building it via a perl expression or by string
expansion or by literal is less important to me.
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.