in reply to How to count substrings in an array?
Edit: forum glitch? As is evident from the title this should have ended up here
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 CKL (Initiate) on Feb 03, 2013 at 07:21 UTC |