So the RE is returning a scalar variable which is in fact what it matched and not the number of times it matched.What you have seen here is a regex match in a list context. If there are capturing parens within the regex it will return what was captured in those parens, and if it lacks capturing parens it will return true or false (unless the /g modifier is in use then it will return what was matched). In a scalar context it merely returns whether the regex matched successfully e.g
See man perlop for more info.my $str = "foo bar baz"; print "[", $str =~ /\w+ /, "]", $/; # list no capture print "[", $str =~ /\w+ /g, "]", $/; # list no capture + /g print "[", $str =~ /(\w+) /, "]", $/; # list and capture print "[". $str =~ /\w+ /, "]", $/; # scalar __output__ [1] [foo bar ] [foo] [1]
_________
broquaint
In reply to Re: Is this magic?
by broquaint
in thread Unexepected regex match return behaviour
by readey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |