Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Above is my example code. The code reads in pairs of unsigned integers from a file and builds a hash of arrays. The file on disk is about 100 meg, and I think reading in 8 bytes at a time is killing the IO. How can I make this speedy?use constant EX_TEMPLATE => 'II'; my $length = 8; my %ValArrayByID = (); # ... open file handle $fh, etc... my $packed_data; while (read($fh, $packed_data, $length)) { my ($ID, $Val) = unpack EX_TEMPLATE, $packed_data; not defined $ValArrayByID{$ID} and $ValArrayByID{$ID} = []; push @{$ValArrayByID{$ID}}, $Val; } # ... close file and use my newly minted hash
|
|---|