m/PATTERN/ : Searches a string for a pattern match, and in scalar context returns true if it succeeds, false if it fails.The 1 you see is simply the value of truth.
Matching in list contextIf the /g option is not used, m// in list context returns a list consisting of the subexpressions matched by the parentheses in the pattern
(...)
The /g modifier specifies global pattern matching -- that is, matching as many times as possible within the string. How it behaves depends on the context. In list context, it returns a list of the substrings matched by any capturing parentheses in the regular expression. If there are no parentheses, it returns a list of all the matched strings, as if there were parentheses around the whole pattern.
In scalar context, each execution of m//g finds the next match, returning true if it matches, and false if there is no further match.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
In reply to Re: assigning regex matches to variables
by CountZero
in thread assigning regex matches to variables
by genghis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |