in reply to Re: 'g' flag with 'qr' (different commands) (updated)
in thread 'g' flag w/'qr'
I was noting the similarity between these forms:
In both of the above, "@matches" will get 2 entries "re" and "xp". I find it unfortunate that if your regexp was doubled, there is no way to directly use qr w/'g' i.e. one must use the m{} or // type form as in:my $foo="regexp"; my @matches = $foo =~ /(re)ge(xp)/; #and my $regex=qr{(re)ge(xp)}; my @matches = $foo =~ $regex;
> perl -we'use strict;use P; my $regex=qr{(re)ge(xp)}; my @matches0 = "regexpregexp" =~ /(re)ge(xp)/g; my @matches = "regexpregexp" =~ $regex; my @matches1 = "regexpregexp" =~ /$regex/g; P "matches=%s, 0=%s, 1=%s", \@matches, \@matches0, \@matches1; ' matches=["re", "xp"], 0=["re", "xp", "re", "xp"], 1=["re", "xp", "re", + "xp"]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: 'g' flag with 'qr' (different commands) (updated)
by AnomalousMonk (Archbishop) on May 30, 2016 at 04:01 UTC | |
|
Re^3: 'g' flag with 'qr' (different commands)
by LanX (Saint) on May 30, 2016 at 11:13 UTC |