if (my @matches = $input_string =~ /$metadata[$_]{"pattern"}/g) {
print $-[1] . "\n"; # this gives me error uninitialized ...
}
print scalar @matches;
gaves me 4, that is ok, but if i use $-[1]
to get start of first match, it gaves me error. Where is problem?
EDIT1: How i can get positions of each match in string? If i have string "ahoj ahoj ahoj" and regexp /ahoj/g, how i can get positions of start and end of each "ahoj" in string?
$-[1]
is the position of the 1st subpattern (something in parentheses within the regular expression). You're probably looking for$-[0]
, the position of the whole pattern? – Scott Lamb Feb 22 '13 at 20:32