Perl Monk, Perl Meditation | |
PerlMonks |
Re3: Optimizing a string processing subby dragonchild (Archbishop) |
on Jan 08, 2003 at 21:00 UTC ( [id://225353]=note: print w/replies, xml ) | Need Help?? |
The @{[]} is a trick to force list context. The reason why list context is important is because of what the regex operator returns. In list context, the regex operator returns a list of what is matched. In scalar context, the regex operator returns whether or not it matched. (In theory, that should be the number of things matched as well, but I couldn't get it to work.)
So, by forcing list context, I get the list of things matched. Then, by converting the list to scalar context, I get the number of things in the list. I'm sure there's a more elegant way than creating two array references on the fly, but that's what I had in 60sec of imperfect memory. ------ Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
In Section
Seekers of Perl Wisdom
|
|