delfarms has asked for the wisdom of the Perl Monks concerning the following question:
Perl equivalent:import re r = re.compile(r'(?P<A> a (?P<B> b))', re.X) m = r.search('ab') for k in m.groupdict(): print k, '=>', m.group(k) # 'A => ab' # 'B => b' print m.group('A') # 'ab' print m.group('B') # 'b'
Perl doesn't enumerate all the keys if a named capture is nested within another. But it it clearly holds the correct value 'b' with the correct key 'B' in the hash. Is this a "feature" or a bug? ;)'ab' =~ /(?<A> a (?<B> b))/x; print "$_ => $+{$_}\n" for (keys(%+)); # 'A => ab' # ... nothing, thats it print "$+{'A'}\n"; # 'ab' print "$+{'B'}\n"; # 'b'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl 5.10 Named Capture Bug?
by SankoR (Prior) on Jul 08, 2008 at 21:10 UTC | |
by moritz (Cardinal) on Jul 08, 2008 at 22:24 UTC | |
|
Re: Perl 5.10 Named Capture Bug?
by moritz (Cardinal) on Jul 08, 2008 at 20:42 UTC | |
by delfarms (Novice) on Jul 08, 2008 at 22:45 UTC | |
|
Re: Perl 5.10 Named Capture Bug?
by maletin (Sexton) on Jul 09, 2008 at 11:57 UTC |