in reply to Faster Hash Slices
Under the assumption that @head stays constant during the loop, do you declare the hash outside of the loop? As the keys of the hash are same every iteration, it would be wasteful, to create and delete the hash structure, allocate memory for the keys, etc every time. So it should be similar to this (leaving chomping aside for the moment):
my @head = split /\t/, <$fh>; my $ref = {}; undef @{$ref}{@head}; # pre-allocate the hash and its keys for( <$fh> ) { @{$ref}{@head} = split /\t/; # do something with the data here }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Faster Hash Slices
by jht (Novice) on Nov 29, 2013 at 02:44 UTC | |
by BrowserUk (Patriarch) on Nov 29, 2013 at 09:01 UTC |