jonneve has asked for the wisdom of the Perl Monks concerning the following question:
The $brackets and $braces variables work as I expected, but the $identifier variable doesn't work right, for example :$braces = qr/(?<braces>\{ ([^\{\}] | (?&braces))*? \} )/x; $brackets = qr/(?<brackets>\( ([^\(\)] | (?&brackets))*? \))/x; $identifier = qr/(?<identifier> \w+($brackets)?( \s*(\.|->)(?&identifi +er))?)/;
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#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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Storing part of a regex in a variable
by Anonymous Monk on Jul 25, 2014 at 17:30 UTC | |
by Anonymous Monk on Jul 25, 2014 at 17:45 UTC | |
by jonneve (Initiate) on Jul 26, 2014 at 05:19 UTC |