Hello all,
I'm writing a rather complex script for converting C++ code to Pascal. A number of patterns or sub-pattern occur rather often, and therefore, I'm trying to put them into variables for later use. Here are my variables :
$braces = qr/(?<braces>\{ ([^\{\}] | (?&braces))*? \} )/x;
$brackets = qr/(?<brackets>\( ([^\(\)] | (?&brackets))*? \))/x;
$identifier = qr/(?<identifier> \w+($brackets)?( \s*(\.|->)(?&identifi
+er))?)/;
The $brackets and $braces variables work as I expected, but the $identifier variable doesn't work right, for example :
#This works
$meth_impl =~ s/((?<identifier> \w+($brackets)?( \s*(\.|->)(?&identifi
+er))?)) \s* \. \s* Trim\(\)/Trim($1)/xg;
#This doesn't match anything:
$meth_impl =~ s/($identifier) \s* \. \s* Trim\(\)/Trim($1)/xg;
As you can see in the example above, I'm using the $brackets variable in both cases, and it works nicely. 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?
Thanks in advance,
Jonathan Neve