Welcome to the Monastery | |
PerlMonks |
Re: Weighted frequency of characters in an array of stringsby Laurent_R (Canon) |
on Jun 07, 2016 at 17:03 UTC ( [id://1165099]=note: print w/replies, xml ) | Need Help?? |
Hm, not entirely sure what will make things faster, but a few ideas:
You probably don't need to store your data into an array, and then go through the array, compute your counters right away when reading the data; Use a hash of counters : $freq{$_} ++; Don't do the division for each single letter: compute the counters, and only at the end, do the four needed divisions; or calculate 1/@data only once into a variable, and use the variable; Using tr// is likely to be faster than a regex to count the letters. For example:
In Section
Seekers of Perl Wisdom
|
|