http://qs1969.pair.com?node_id=1159245

james28909 has asked for the wisdom of the Perl Monks concerning the following question:

I have this script I have written, which seems to work (or it seems to haha), but it is lacking in speed. For a 16 MB file it takes 9-10 secs for it to complete and I will need to use it on 256 MB files in the future. I was hoping I could get some help in speeding it up, if at all possible.
use strict; use warnings; open my $file, '<', shift; binmode($file); my %seen = (); while ( read( $file, my $buf, 1 ) ) { if ( !$seen{$buf} ) { $seen{$buf} = 1; } else { $seen{$buf}++; } } print "$_ - $seen{$_}\n" for ( keys %seen );
Any help in speeding this up would be much appreciated. :)