in reply to Re: calling subroutines within a regular expression?
in thread calling subroutines within a regular expression?

One more for "fun"-

if ( $s =~ /${+REGEX}/ ) { ...

Replies are listed 'Best First'.
Re^3: calling subroutines within a regular expression?
by AnomalousMonk (Archbishop) on Apr 04, 2009 at 00:43 UTC
    This doesn't seem to work:
    >perl -wMstrict -le "use constant RX => qr{ [atc]{3} }xms; my $s = 'the cat in the hat'; print 'found' if $s =~ /${+RX}/; print qq{found a $1} if $s =~ /(${+RX})/; " Use of uninitialized value in regexp compilation ... found Use of uninitialized value in concatenation (.) or string ... found a

      You're right. It looked like it worked on the original to me because it matched "cat" against "" which "found" it. The + is a way to force constants to evaluate, also works, in some contexts, with spelling it out as the sub it is, RX(). Doesn't work here though. :(