in reply to Re: Re: Creating regex from arrays
in thread Creating regex from arrays

You're right, timtowtdi sitting on my shoulder. I do like that construction, though. IMO, it's more concise and less visually noisy. True, it depends on a trick from the second tier of quote operator details, but I think the sparse notation and localization of $" pretty well telegraph what the trick is.

I don't know if there is any performance benefit, other than what's obtained from constructing a compiled regex with qr//. That could as well be done with join. I've never benchmarked this.

A minor refinement of the code, to assign $re where it is declared:

my $re = do { local $" = '|'; qr/@array/; };
or, if metacharacters may be a problem,
my $re = do { local $" = '|'; qr/@{[map {quotemeta} @array]}/; };

After Compline,
Zaxo