XP is just a number | |
PerlMonks |
Re: Getting the number of times a regexp matchesby dchetlin (Friar) |
on Dec 07, 2000 at 18:33 UTC ( [id://45500]=note: print w/replies, xml ) | Need Help?? |
No one mentioned the canonical and most Perlish way to do this:
my $count = () = $str =~ m/pattern/g; I suspect it offers little benefit in terms of efficiency, and can be confusing contextually. I do feel that it's the most succinct and elegant, however. Update: My apologies; while I was writing this and getting distracted, it was mentioned ahead of me, and an interesting discussion of it followed. Ah well. -dlc
In Section
Seekers of Perl Wisdom
|
|