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

I did indeed try it myself some while ago, but eventually gave up on account of 2 things:

In retrospect, it occurs to me that I used the latter as a convenient excuse/motive for giving up on attempts to achieve the former.

A user level that continues to overstate my experience :-))
  • Comment on Re^3: calling subroutines within a regular expression?

Replies are listed 'Best First'.
Re^4: calling subroutines within a regular expression?
by AnomalousMonk (Archbishop) on Apr 05, 2009 at 09:39 UTC
    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
      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 :-))