in reply to How to count substrings in an array?
The "goatse operator" can make this a bit shorter and faster: $count =()= $string =~ /RE/; counts the number of matches in $string, so
does what you want. It evaluates the regex in list context so it returns the list of matches and then forces it to scalar context without assigning the list anywhere.my $count; for(@array) { $count +=()= /RE/g; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to count substrings in an array?
by Athanasius (Archbishop) on Feb 03, 2013 at 08:20 UTC | |
Re^2: How to count substrings in an array?
by smls (Friar) on Feb 03, 2013 at 08:11 UTC | |
by LanX (Saint) on Feb 03, 2013 at 12:01 UTC | |
by choroba (Cardinal) on Feb 03, 2013 at 20:07 UTC | |
by LanX (Saint) on Feb 03, 2013 at 20:45 UTC | |
by AnomalousMonk (Archbishop) on Feb 03, 2013 at 11:20 UTC |
In Section
Seekers of Perl Wisdom