in reply to Re: Re: Good Idiom for Matching List?
in thread Good Idiom for Matching List?

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