in reply to Re^2: Split operator in perl
in thread Split operator in perl
As a beginner to Perl, maybe you shouldn't worry about what weird results split will give if you give it weird inputs. I bet most Perl experts would have to guess at what 'ab'=~/(a|b)+/ returns (although they would likely guess correctly). More important would be to learn how to use split properly.
The regular expressions should identify the separator. In your case, it doesn't appear to be used to match a separator, so split is probably not the best tool for the job.
You'll rarely want to use captures in a split pattern. When you do, what the captures match is returned in split's result.
Using a quantifier on a capture doesn't make sense. If you want to group things in patterns, use (?:...) instead of (...). The latter is much slower since it remembers what the parens matched, and has side effects in split.
|
|---|