in reply to Re: Computing the percentage of certain characters in a file
in thread Computing the percentage of certain characters in a file
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Computing the percentage of certain characters in a file
by AnomalousMonk (Archbishop) on Aug 06, 2014 at 08:39 UTC | |
It sounds like this might have been an XY Problem: "How do I count the occurrences of each character in a string/file/etc?" (Caution: The following solution only works for byte characters (i.e., 1 byte == 1 character), not Unicode characters.)
| [reply] [d/l] |
by james28909 (Deacon) on Aug 07, 2014 at 04:19 UTC | |
But, i am going to study this code because it would have saved me hours if i knew exactly how do it this way in the first place. and thanks for sharing :) I tried to use eval with tr/// but it was returning unexpected results, and was probably something i was doing wrong. I did think about how i could do a loop or something, but the only way was with s///g and it took a while longer to accomplish what i was after. tho the script i made works great, yours is alot shorter and is faster. | [reply] [d/l] |
by AnomalousMonk (Archbishop) on Aug 07, 2014 at 09:02 UTC | |
Here's another approach that may be a little faster than my previous one (but it will be nowhere near 3 - 4 seconds for 256 MB!).
... how HxD is able to do it ... ... is by writing the code in C or some such compiled language — at least, I'd be willing to bet doughnuts to dollars that's the case. You, too, can do this with Inline::C! (Update: See also Inline::C::Cookbook.) In fact, the array-based approach in the code example above should, I think, convert very neatly to C. The learning curve for Inline::C is not too bad (assuming you know C!) and well worth the effort if you have a need for speed! (I need to brush up on Inline::C myself, so if I have some time later, I may play around with this.) | [reply] [d/l] [select] |
by james28909 (Deacon) on Aug 07, 2014 at 22:28 UTC | |