in reply to Re: bracket processing
in thread bracket processing
my $delim = '([{<';
my $prefix = qr{[^$delim]*};
As a general practice, I find it's much safer to interpolate strings like $delim into regexes using \Q \E metaquote escapes:
my $delim = '([{<';
my $prefix = qr{[^\Q$delim\E]*};
Of course, one could metaquote the string variable upon definition:
my $delim = quotemeta '([{<';
but that might screw up subsequent use of the string; e.g., its use in something like
my @parts = extract_bracketed($string, $delim, $prefix);
might become problematic.
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: bracket processing
by kcott (Archbishop) on Apr 01, 2020 at 00:37 UTC | |
by AnomalousMonk (Archbishop) on Apr 01, 2020 at 18:23 UTC | |
by kcott (Archbishop) on Apr 02, 2020 at 01:44 UTC | |
by AnomalousMonk (Archbishop) on Apr 02, 2020 at 03:16 UTC |