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

IIRC, PBP deprecates the use of constant in favor of the Readonly module, which gives you (among other things) read-only scalars which interpolate as expected in double-quotish things like strings and regexes.

I can't test this right now, but I think the following works and also gives you a more elegant regex interpolation:

use warnings; use strict; use Readonly; Readonly my $BAR => qr{ bar }xms; my $string = q{fie foo bar baz barf}; print qq{found $1} if $string =~ m{ foo \s* ($BAR) \s* baz }xms;
Should print:
found bar

Replies are listed 'Best First'.
Re^5: calling subroutines within a regular expression?
by Bloodnok (Vicar) on Apr 05, 2009 at 10:31 UTC
    You're not wrong (about the deprecation in favour of Readonly) ... and yes, I wholeheartedly agree with you WRT the elegance of the result.

    A user level that continues to overstate my experience :-))