in reply to Letter frequencies
Well, I tested it, and this is the tail of the output, run with time perl .... (too lazy for benchmarking):undef $/; #just read the whole STDIN in once: $_=<>; tr/ \t\n\r//d; #remove all spaces map{ $count{ $_ }++;} split //; #the actual count foreach $key (sort(keys %count)) #OK, one loop to print { print "$key\t$count{$key}\n"; $total += $count{$key}; } print "Total\t$total\n";
And it looks to me like a 150kb file that has been counted in just 0.62 s. Looks pretty impressive to me. I don't consider myself to be a decent perl coder, so I would appreciate any comments to this....ó 18 ô 93 õ 12 ö 16 ÷ 12 ø 25 ù 2 ú 3 û 1 ü 2 ý 6 þ 2 ÿ 6 0.26user 0.05system 0:00.62elapsed 49%CPU (0avgtext+0avgdata 0maxresid +ent)k 0inputs+0outputs (275major+797minor)pagefaults 0swaps [jeroen@rulffk] time: 11:49:31 1 jobs wd: ~ (12.011Mb) $ ls -l test.txt -rw-rw-r-- 1 jeroen jeroen 150271 Aug 17 11:40 test.txt [jeroen@rulffk] time: 11:50:04 1 jobs wd: ~ (12.011Mb)
Have fun,
Jeroen
I was dreaming of guitarnotes that would irritate an executive kind of guy (FZ)
PP: I just took a .txt file, but it wasn't a text-file after all. Maybe some word (ugh!) document or whatever.
Update Removed square brackets from tr///d, as pointed out by merlyn. And changed a funny typo (s/while/whole/). Justifies my remark on decent coding, I'm afraid :-<. Another update: added the total number.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Letter frequencies
by merlyn (Sage) on Nov 24, 2000 at 18:16 UTC | |
by jeroenes (Priest) on Nov 24, 2000 at 18:42 UTC |