Re: how to get references from imbricated capturing parenthesis ?



marin schreef:

I'm trying to get references from a simple regular
exepression like this :

"a40d7412" =~ /(([[:xdigit:]]{2})*)/;
print "$1: <$2><$3><$4><$5>\n";

This prints :
a40d7412: <12><><><>

How to get all references

Verbose variant:

#!/usr/bin/perl
use strict;
use warnings;

my $s = 'a40d7412';

my ($m, @m) = $s =~
/(
[[:xdigit:]] {2} # 2 hex-digits
)/xg; # each

print "$m: <",
join('><', @m),
">\n";
__END__


Terse variant:

@m = $s =~ /../g; # no capturing () needed
{ local $" = '><'; # see perlvar
print shift(@m), ": <@m>\n";
}


See also `perldoc -f pack` (the H-template).


and not the last one in the second
parenthesis pair ?


You shouldn't suggest the wrong approach as part of the solution.
:)

--
Affijn, Ruud

"Gewoon is een tijger."
.