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
is treated literally. At least, that's what I think, considering the absense of any examples of strings to match.<identifier> \w+
Also, stop writing complex regexes on one line. Perl doesn't have to be write-only, you know?
In reply to Re: Storing part of a regex in a variable
by Anonymous Monk
in thread Storing part of a regex in a variable
by jonneve
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |