I think my problem with this construct, that is, why I think it
should be natural and simple, is that what I'm writing is basically a composition of two functions.
my $x= f();
$x= g($x);
That is, the first result is the argument to the second line, and is not used for anything else.
So I would naturally write it as my $x=g(f()); instead, as one expression without a named temporary.
Here's the rub: qr// does not use the normal function syntax. It uses the quoting syntax, which doesn't naturally handle arbitrary nesting. So, use the @{[]} hack (or worse, if the list context would be a problem) or use Interpolation to work-around.
But what I really want is a callable function that takes a string and returns the corresponding compiled regex. We have quotemeta and lc that let us access special syntax features in a normal functional way; I want that for everything.
sub mk_qr ($)
{
eval "qr/$_[0]/";
}
—John
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.