G'day perl-diddler,
"So how can I attach the "/g" modifier to my "qr" regex ... ?"
The 'g' modifier is used by m// and s/// to direct how a regex is to be used (single match, global substitution, etc.); it does not affect the regex itself. qr// has no 'g' modifier. Here's links to all three (note the modifier lists):
The 'g' modifier is not part of qr//'s syntax and, if used, syntax errors are raised (as expected).
$ perl -wE 'my $re = qr{A}g' Unknown regexp modifier "/g" at -e line 1, near "= " Execution of -e aborted due to compilation errors.
You also can't do it with the re pragma's '/flags' mode:
$ perl -wE 'use re "/g"' Unknown regular expression flag "g" at -e line 1.
See also:
On a side note — related to what you're doing but not the current problem at hand — are you familiar with the '(?<flags>:<pattern>)' regex construct described in perlre: Extended Patterns: (?adluimnsx-imnsx:pattern)? This construct, and qr//'s interpolating, allows you to write something like this:
$ perl -wE 'my ($p, $f) = (A => "x"); my $re = qr{(?$f: $p )}; say $re +' (?^u:(?x: A ))
Now you control the available flags and don't have to worry about qr//'s modifiers.
By the way, you can't add a 'g' modifier using this method either. :-)
$ perl -wE 'qr{(?g:)}' Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/(?g < +-- HERE :)/ at -e line 1.
— Ken
In reply to Re: 'g' flag w/'qr'
by kcott
in thread 'g' flag w/'qr'
by perl-diddler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |