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

Hi LanX,

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

Thanks, that's an excellent piece of inspiration! Just to take that idea a little further and add support for /i and the like:

sub qre (&;$) { my $re = shift->(); eval 'qr/$re/'.(shift//'') || die $@ } my $regex = qre{ join '|', qw/foo bar/ }'i'; print "$regex\n"; __END__ (?^i:foo|bar)

Not that I'm going to start using this right away, for now this is just to satisfy my curiosity ;-)

-- Hauke D