in reply to Getting information about regexp matches
Just to note: since $1 and its ilk will keep their values if the regex fails to match, make sure you wrap this all in a conditional. I'm not sure about what's so bad about using length here; the grouping number shift is going to be a problem anyway, if your code's not setting $regexp, how will you know whether it has groupings at all? (and if so, how many). Of course, if you want to nab those matches, you can always use a nice listy assignment like:
if (my ($foo, $bar, @reg_groups) = $string =~ /^(.*?)($regexp)/) { # $foo = $1, $bar = $2, @reg_groups = all the matching groups from $ +regexp my $totength = length $foo.$bar; my $foolength = length $foo; # whatever happens next }
HTH
|
|---|