in reply to Storing part of a regex in a variable

Could the problem be that my $identifier variable itself includes the $brackets variable? Do I need to eval it or something to force it to interpolate it correctly?
No. No.
$identifier = qr/(?<identifier> \w+($brackets)?( \s*(\.|->)(?&identifi +er))?)/;

It seems you forgot /x there. Your last regex (in substitution) looks this when compiled:

(?^:((?^:(?<identifier> \w+... (etc)

And

     (?^:

means

Starting in Perl 5.14, a "^" (caret or circumflex accent) immediately after the "?" is a shorthand equivalent to "d-imsx".
So, whitespace in
<identifier> \w+
is treated literally. At least, that's what I think, considering the absense of any examples of strings to match.

Also, stop writing complex regexes on one line. Perl doesn't have to be write-only, you know?

Replies are listed 'Best First'.
Re^2: Storing part of a regex in a variable
by Anonymous Monk on Jul 25, 2014 at 17:45 UTC
Re^2: Storing part of a regex in a variable
by jonneve (Initiate) on Jul 26, 2014 at 05:19 UTC
    I can't believe it was so simple! It all makes a lot more sense now! As for the one-liners... you're right, and that's why I was trying to use variables to split things up : it's a lot more readable that way. Thanks for your help!