http://qs321.pair.com?node_id=1179861


in reply to Re: Feature Idea: qr//e
in thread Feature Idea: qr//e (updated with solutions)

Having your other post in mind I misread your question, sorry.

you don't want to operate on an array but a code-block

Would you accept something like the following as sufficiently equivalent?

sub qre(&;@) { my $block = shift; my $str = $block->(@_); return qr/$str/; }

(not tested)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

udpate

some functional code:

use Data::Dump; sub qre(&;@) { my $block = shift; my $str = $block->(@_); return qr/$str/; } sub ored { return join '|', map {quotemeta} @_ } sub oredraw { return join '|', @_ } my @strings = qw/. | %/ ; dd qre {join '|', map {quotemeta} @strings }; dd qre \&ored, @strings; dd qre \&oredraw, @strings;