knight has asked for the wisdom of the Perl Monks concerning the following question:
But I'm doing this with two very similar expressions, the first for normal unadorned variable names ("%FOO") and the second for variable names enclosed in braces ("%{FOO}"). Can anyone suggest how these two might be combined, hopefully in a way that speeds up the processing? The obvious technique of sticking '*' after the braces in the regexes loses because I don't want to match unbalanced braces like "%FOO}".# % expansion. %% gets converted to % later, so expand any # %keyword construction that doesn't have a % in front of it # (modulo multiple %% pairs in between). while (($str =~ s/(^|[^\%](?:\%\%)*)\%([_a-zA-Z]\w*)/"$1".$env->{$2}/g +e) || ($str =~ s/(^|[^\%](?:\%\%)*)\%\{([_a-zA-Z]\w*)\}/"$1".$env->{$ +2}/ge)) {}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how can I combine these expressions?
by plaid (Chaplain) on Jul 27, 2000 at 03:27 UTC | |
by Ovid (Cardinal) on Jul 27, 2000 at 03:47 UTC | |
by knight (Friar) on Jul 27, 2000 at 20:29 UTC | |
|
Re: how can I combine these expressions?
by chromatic (Archbishop) on Jul 27, 2000 at 02:44 UTC | |
by Ovid (Cardinal) on Jul 27, 2000 at 03:02 UTC | |
|
(Ovid) Re: how can I combine these expressions?
by Ovid (Cardinal) on Jul 27, 2000 at 03:20 UTC | |
|
Re: how can I combine these expressions?
by lhoward (Vicar) on Jul 27, 2000 at 03:03 UTC |